mbox series

[v2,00/37] ALSA: Add MIDI 2.0 support

Message ID 20230523075358.9672-1-tiwai@suse.de (mailing list archive)
Headers show
Series ALSA: Add MIDI 2.0 support | expand

Message

Takashi Iwai May 23, 2023, 7:53 a.m. UTC
Hi,

this is a revised patch set for adding the support of MIDI 2.0
functionality.  Only a few minor updates since v1 as below:

* Bump CTL protocol version to 2.0.9
* Add two more ioctls for control API to receive UMP EP and block info
* Minor compile warning fixes
* Documentation fix and addition of two new ioctls
* Put acks

The latest code is found in topic/midi20 branch of sound git tree.

And below is the cover letter of v1, which is still valid:

Hi,

this is a (largish) patch set for adding the support of MIDI 2.0
functionality, mainly targeted for USB devices.  MIDI 2.0 is a
complete overhaul of the 40-years old MIDI 1.0.  Unlike MIDI 1.0 byte
stream, MIDI 2.0 uses packets in 32bit words for Universal MIDI Packet
(UMP) protocol.  It supports both MIDI 1.0 commands for compatibility
and the extended MIDI 2.0 commands for higher resolutions and more
functions.

For supporting the UMP, the patch set extends the existing ALSA
rawmidi and sequencer interfaces, and adds the USB MIDI 2.0 support to
the standard USB-audio driver.

The rawmidi for UMP has a different device name (/dev/snd/umpC*D*) and
it reads/writes UMP packet data in 32bit CPU-native endianness.  For
the old MIDI 1.0 applications, the legacy rawmidi interface is
provided, too.

As default, USB-audio driver will take the alternate setting for MIDI
2.0 interface, and the compatibility with MIDI 1.0 is provided via the
rawmidi common layer.  However, user may let the driver falling back
to the old MIDI 1.0 interface by a module option, too.

A UMP-capable rawmidi device can create the corresponding ALSA
sequencer client(s) to support the UMP Endpoint and UMP Group
connections.  As a nature of ALSA sequencer, arbitrary connections
between clients/ports are allowed, and the ALSA sequencer core
performs the automatic conversions for the connections between a new
UMP sequencer client and a legacy MIDI 1.0 sequencer client.  It
allows the existing application to use MIDI 2.0 devices without
changes.

The MIDI-CI, which is another major extension in MIDI 2.0, isn't
covered by this patch set.  It would be implemented rather in
user-space.

Roughly speaking, the first half of this patch set is for extending
the rawmidi and USB-audio, and the second half is for extending the
ALSA sequencer interface.

The patch set is based on 6.4-rc2 kernel, but all patches can be
cleanly applicable on 6.2 and 6.3 kernels, too (while 6.1 and older
kernels would need minor adjustment for uapi header changes).

The updates for alsa-lib and alsa-utils will follow shortly later.

The author thanks members of MIDI Association OS/API Working Group,
especially Andrew Mee, for great helps for the initial design and
debugging / testing the drivers.


Takashi

---

Takashi Iwai (37):
  ALSA: rawmidi: Pass rawmidi directly to snd_rawmidi_kernel_open()
  ALSA: rawmidi: Add ioctl callback to snd_rawmidi_global_ops
  ALSA: rawmidi: UMP support
  ALSA: rawmidi: Skip UMP devices at SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE
  ALSA: ump: Add ioctls to inquiry UMP EP and Block info via control API
  ALSA: ump: Additional proc output
  ALSA: usb-audio: Manage number of rawmidis globally
  ALSA: usb-audio: Define USB MIDI 2.0 specs
  ALSA: usb-audio: USB MIDI 2.0 UMP support
  ALSA: usb-audio: Get UMP EP name string from USB interface
  ALSA: usb-audio: Trim superfluous "MIDI" suffix from UMP EP name
  ALSA: usb-audio: Create UMP blocks from USB MIDI GTBs
  ALSA: ump: Redirect rawmidi substream access via own helpers
  ALSA: ump: Add legacy raw MIDI support
  ALSA: usb-audio: Enable the legacy raw MIDI support
  ALSA: usb-audio: Inform inconsistent protocols in GTBs
  ALSA: seq: Clear padded bytes at expanding events
  ALSA: seq: Add snd_seq_expand_var_event_at() helper
  ALSA: seq: Treat snd_seq_client object directly in client drivers
  ALSA: seq: Drop dead code for the old broadcast support
  ALSA: seq: Check the conflicting port at port creation
  ALSA: seq: Check validity before creating a port object
  ALSA: seq: Prohibit creating ports with special numbers
  ALSA: seq: Introduce SNDRV_SEQ_IOCTL_USER_PVERSION ioctl
  ALSA: seq: Add UMP support
  ALSA: seq: Add port inactive flag
  ALSA: seq: Support MIDI 2.0 UMP Endpoint port
  ALSA: seq: Add port direction to snd_seq_port_info
  ALSA: seq: Add UMP group number to snd_seq_port_info
  ALSA: seq: Automatic conversion of UMP events
  ALSA: seq: Allow suppressing UMP conversions
  ALSA: seq: Bind UMP device
  ALSA: seq: ump: Create UMP Endpoint port for broadcast
  ALSA: seq: Add ioctls for client UMP info query and setup
  ALSA: seq: Print UMP Endpoint and Block information in proc outputs
  ALSA: seq: Add UMP group filter
  ALSA: docs: Add MIDI 2.0 documentation

 Documentation/sound/designs/index.rst    |    1 +
 Documentation/sound/designs/midi-2.0.rst |  351 +++++++
 include/linux/usb/midi-v2.h              |   94 ++
 include/sound/asequencer.h               |    4 +
 include/sound/rawmidi.h                  |   15 +-
 include/sound/seq_device.h               |    1 +
 include/sound/seq_kernel.h               |   10 +
 include/sound/ump.h                      |  175 ++++
 include/sound/ump_msg.h                  |  540 ++++++++++
 include/uapi/sound/asequencer.h          |   83 +-
 include/uapi/sound/asound.h              |   62 +-
 sound/core/Kconfig                       |   13 +
 sound/core/Makefile                      |    3 +
 sound/core/rawmidi.c                     |  264 +++--
 sound/core/rawmidi_compat.c              |    4 +
 sound/core/seq/Kconfig                   |   14 +
 sound/core/seq/Makefile                  |    3 +
 sound/core/seq/seq_clientmgr.c           |  577 +++++++----
 sound/core/seq/seq_clientmgr.h           |   27 +-
 sound/core/seq/seq_compat.c              |    3 +
 sound/core/seq/seq_dummy.c               |    9 +
 sound/core/seq/seq_memory.c              |   98 +-
 sound/core/seq/seq_memory.h              |   19 +-
 sound/core/seq/seq_midi.c                |   12 +-
 sound/core/seq/seq_ports.c               |   47 +-
 sound/core/seq/seq_ports.h               |   23 +-
 sound/core/seq/seq_ump_client.c          |  464 +++++++++
 sound/core/seq/seq_ump_convert.c         | 1203 ++++++++++++++++++++++
 sound/core/seq/seq_ump_convert.h         |   22 +
 sound/core/seq/seq_virmidi.c             |    1 +
 sound/core/ump.c                         |  668 ++++++++++++
 sound/core/ump_convert.c                 |  520 ++++++++++
 sound/core/ump_convert.h                 |   43 +
 sound/usb/Kconfig                        |   11 +
 sound/usb/Makefile                       |    1 +
 sound/usb/card.c                         |   12 +-
 sound/usb/midi.c                         |    7 +-
 sound/usb/midi.h                         |    5 +-
 sound/usb/midi2.c                        | 1190 +++++++++++++++++++++
 sound/usb/midi2.h                        |   33 +
 sound/usb/quirks.c                       |    8 +-
 sound/usb/usbaudio.h                     |    2 +
 42 files changed, 6306 insertions(+), 336 deletions(-)
 create mode 100644 Documentation/sound/designs/midi-2.0.rst
 create mode 100644 include/linux/usb/midi-v2.h
 create mode 100644 include/sound/ump.h
 create mode 100644 include/sound/ump_msg.h
 create mode 100644 sound/core/seq/seq_ump_client.c
 create mode 100644 sound/core/seq/seq_ump_convert.c
 create mode 100644 sound/core/seq/seq_ump_convert.h
 create mode 100644 sound/core/ump.c
 create mode 100644 sound/core/ump_convert.c
 create mode 100644 sound/core/ump_convert.h
 create mode 100644 sound/usb/midi2.c
 create mode 100644 sound/usb/midi2.h

Comments

Symbolic Debugger June 13, 2023, 12:41 p.m. UTC | #1
Hello I have a few questions:

1. As default, USB-audio driver will take the alternate setting for MIDI 2.0 interface:  Does this mean that the ALSA driver will default to Alt Function 1 if it exists ? 
2. What happens when using a kernel that does not support Alt Function 1 (MIDI 2.0) and  device with a  (much longer) MIDI 2.0 descriptor is attached ?
3. " However, user may let the driver falling back to the old MIDI 1.0 interface by a module option, too."
     Can or how it this done via the ALSA API  ? If the switch is made, does an ALSA client require to re-enumerate all the ports ?
4. Is there a way to force a specific device (port) to Legacy MIDI 1.0 ?
5. Is there a way , via ALSA, to select UMP MIDI 1.0 protocol instead of MIDI 2.0 UMP protocol.
6. To which protocol does the driver default ? UMP MIDI 1.0 or UMP MIDI 2.0 ? 
7. Does the driver do anything related to  Jitter Reduction ? How/is this supported via the ALSA API ?a
8. Does the driver do anything related to  Bandwidth restriction ?  How/is this supported via the ALSA API ?
9. Are/will UMP streaming messages be supported ? (new feature in MIDI 2.0 specification), if yes, how ?
10. Is function block information supported via ALSA, i.e added in the ALSA Port information ?
Takashi Iwai June 13, 2023, 12:53 p.m. UTC | #2
On Tue, 13 Jun 2023 14:41:07 +0200,
happy.debugging@gmail.com wrote:
> 
> Hello I have a few questions:
> 
> 1. As default, USB-audio driver will take the alternate setting for MIDI 2.0 interface:  Does this mean that the ALSA driver will default to Alt Function 1 if it exists ? 

Yes.

> 2. What happens when using a kernel that does not support Alt Function 1 (MIDI 2.0) and  device with a  (much longer) MIDI 2.0 descriptor is attached ?

It falls back to MIDI 1.0 interface.

> 3. " However, user may let the driver falling back to the old MIDI 1.0 interface by a module option, too."
>      Can or how it this done via the ALSA API  ?

You can't.  Only via a module option or kconfig.

> If the switch is made, does an ALSA client require to re-enumerate all the ports ?
> 4. Is there a way to force a specific device (port) to Legacy MIDI 1.0 ?

If demanded, we can implement a device-specific quirk for that.

> 5. Is there a way , via ALSA, to select UMP MIDI 1.0 protocol instead of MIDI 2.0 UMP protocol.

Use the UMP 1.1 Streaming command to switch the protocol.

> 6. To which protocol does the driver default ? UMP MIDI 1.0 or UMP MIDI 2.0 ? 

Whatever the device sets as default.

> 7. Does the driver do anything related to  Jitter Reduction ? How/is this supported via the ALSA API ?a

JRTS is sent as normal UMP packet (also as sequencer events).
No particular API is provided for JRTS, so far.

> 8. Does the driver do anything related to  Bandwidth restriction ?  How/is this supported via the ALSA API ?

Currently no restriction is.
The bandwidth is provided via the API, but it's only for information.

> 9. Are/will UMP streaming messages be supported ? (new feature in MIDI 2.0 specification), if yes, how ?

It was already implemented in kernel UMP core.  See the recent posts.

> 10. Is function block information supported via ALSA, i.e added in the ALSA Port information ?

Ditto.


Takashi
Symbolic Debugger June 13, 2023, 1:24 p.m. UTC | #3
Many thanks, it seems that you already receive the new specs :-) 

BTW I just joined this list, any my email address is shown in posts instead of the username as for other member
is there a contact for this list (webmaster) to discuss this ? I could not find any contact for the admin.

Item 5. assume this is 7.1.6.2 Stream Configuration Request /  7.1.6.4 Stream Configuration Notification.  
Can it be done via the ALSA API ?
Takashi Iwai June 13, 2023, 1:31 p.m. UTC | #4
On Tue, 13 Jun 2023 15:24:11 +0200,
Happy Debugging wrote:
> 
> Many thanks, it seems that you already receive the new specs :-) 

Yes, I was involved with the spec definition, too.

And, Linux/ALSA patches have been internally reviewed and discussed
with MAA MIDI 2.0 WG for months before publishing.

> BTW I just joined this list, any my email address is shown in posts instead of the username as for other member
> is there a contact for this list (webmaster) to discuss this ? I could not find any contact for the admin.

I guess it's rather your mailer setup?

> Item 5. assume this is 7.1.6.2 Stream Configuration Request /  7.1.6.4 Stream Configuration Notification.  
> Can it be done via the ALSA API ?

You can send a UMP packet.


Takashi
Symbolic Debugger June 13, 2023, 3:23 p.m. UTC | #5
So great that the Linux community got involved early. :-)  Mailer issue resolved, It seems it needs some time to take effect.
"You can send an UMP packet" => it means to the raw midi device /dev/snd/umpC*D* ? That is not via an ALSA API call  (yet) ?
Symbolic Debugger June 14, 2023, 6:01 a.m. UTC | #6
I could not find the changes and UMP source files on https://github.com/torvalds/linux/tree/master/sound,  is that correct ?
I am trying to build a kernel with UMP support for testing UMP on a custom made development board.
Takashi Iwai June 14, 2023, 6:09 a.m. UTC | #7
On Wed, 14 Jun 2023 08:01:39 +0200,
Symbolic Debugger wrote:
> 
> I could not find the changes and UMP source files on https://github.com/torvalds/linux/tree/master/sound,  is that correct ?
> I am trying to build a kernel with UMP support for testing UMP on a custom made development board.

All MIDI 2.0 stuff will be merged to 6.5 kernel.
Currently it's found in linux-next or sound.git subsystem tree.

In sound.git tree, you can find some branches for the use on older
kernels, too (topic/midi20, topic/midi20-6.1.y, topic/midi20-5.15.y,
topic/midi20-5.10.y, topic/midi20-5.4.y).


Takashi
Takashi Iwai June 14, 2023, 6:53 a.m. UTC | #8
On Wed, 14 Jun 2023 08:09:37 +0200,
Takashi Iwai wrote:
> 
> On Wed, 14 Jun 2023 08:01:39 +0200,
> Symbolic Debugger wrote:
> > 
> > I could not find the changes and UMP source files on https://github.com/torvalds/linux/tree/master/sound,  is that correct ?
> > I am trying to build a kernel with UMP support for testing UMP on a custom made development board.
> 
> All MIDI 2.0 stuff will be merged to 6.5 kernel.
> Currently it's found in linux-next or sound.git subsystem tree.
> 
> In sound.git tree, you can find some branches for the use on older
> kernels, too (topic/midi20, topic/midi20-6.1.y, topic/midi20-5.15.y,
> topic/midi20-5.10.y, topic/midi20-5.4.y).

FWIW, sound.git tree is found at:
  https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/


Takashi
Symbolic Debugger June 15, 2023, 11:39 a.m. UTC | #9
That was indeed worth a lot. Built this sound.git on two machines:

make menuconfig
enabled:
* MIDI 2.0 Support by USB audio driver
* Support for UMP Events
Save to .config
make

Found to .ko files in usb folder:
snd-usb-audio.ko
sndmidi-lib.ko

Ubuntu 22.04 LTS (Linux H3 5.19.0-43-generic #44~22.04.1-Ubuntu) with 5.19 HWE Stack Option
sudo insmod snd-usb-audio.ko
insmod: ERROR: could not insert module snd-usb-audio.ko: Invalid module format

Ubuntu 23.04 (runs in KVM)  (Linux Ubuntu 6.2.0-20-generic)
sudo insmod snd-usb-audio.ko
insmod: ERROR: could not insert module snd-usb-audio.ko: Unknown symbol in module
[37207.309239] snd_usb_audio: Unknown symbol snd_ump_receive (err -2)
[37207.309275] snd_usb_audio: Unknown symbol media_entity_pads_init (err -2)
[37207.309289] snd_usb_audio: Unknown symbol media_remove_intf_link (err -2)
[37207.309311] snd_usb_audio: Unknown symbol snd_usbmidi_resume (err -2)
[37207.309420] snd_usb_audio: Unknown symbol media_device_delete (err -2)
[37207.309434] snd_usb_audio: Unknown symbol snd_ump_endpoint_new (err -2)
[37207.309440] snd_usb_audio: Unknown symbol media_devnode_create (err -2)
[37207.309449] snd_usb_audio: Unknown symbol media_device_unregister_entity (err -2)
[37207.309460] snd_usb_audio: Unknown symbol snd_usbmidi_disconnect (err -2)
[37207.309468] snd_usb_audio: Unknown symbol media_device_usb_allocate (err -2)

Can it be done on 6.2 or 5.15 ?

How to insert the new module or build it so it can be used with a current kernel ?
How to proceed in case the existing module is use (rmmod) ?  Canoncial does not provide kernel sources for newer kernels than 6.2 , like 6.4.0.rc2 of this sound.git, at least could not find them, but I did successfully built the 6.2 and 5.15 Ubuntu distro kernels already from their respective sources. Just copy the sound/usb and sound/core files over the current kernel sources, recompile it (of-course with and updated version number).
Symbolic Debugger June 16, 2023, 12:23 p.m. UTC | #10
Well never mind... Finally ! 

uname -a
Linux Ubuntu 6.4.0-rc6-next-20230615 #3 SMP PREEMPT_DYNAMIC Fri Jun 16 17:48:44 CST 2023 x86_64 x86_64 x86_64 GNU/Linux
Takashi Iwai June 16, 2023, 12:27 p.m. UTC | #11
On Fri, 16 Jun 2023 14:23:02 +0200,
Symbolic Debugger wrote:
> 
> Well never mind... Finally ! 
> 
> uname -a
> Linux Ubuntu 6.4.0-rc6-next-20230615 #3 SMP PREEMPT_DYNAMIC Fri Jun 16 17:48:44 CST 2023 x86_64 x86_64 x86_64 GNU/Linux

Good to hear that you made it :)

Actually, backporting the patches to 6.2 should be trivial, too.
You can simply rebase the commits between v6.4-rc2..topic/midi20 onto
6.2 or 6.3 base.

As mentioned, the backports for other LTS branches are found on
sound.git tree, which required a few more pieces and some
corrections.


Takashi
Symbolic Debugger June 16, 2023, 2:17 p.m. UTC | #12
Thanks a lot for the reply. I could try to re-base/backport the change onto the 6.2 kernel, but I am not very versed in git.. If there is a pointer to where how to do this backport, would be great. Now that I am on 6.4, the first step is to let the umpCxDx USB MIDI 2.0 device show up and then enumerate the ALSA ports (RAW or Sequencer) [ just C code] to find it there as well. P.S: I am not sure if this is the right place for the long conversation and support on this. I could create a server/channel on Discord.
Symbolic Debugger June 17, 2023, 3:07 p.m. UTC | #13
An Attempt to replay the changes to 6.2 :
starting with linux-next (On branch next-20230614) as master
According to tag 6.4-rc2 the  commit for it is  f81fe2a4874338a1bfc599cae903a6101217b0a5
# reset the  master to 6.4-rc2:
$git reset --hard  581fe2a4874338a1bfc599cae903a6101217b0a5
$git checkout v6.2
Previous HEAD position was f1fcbaa18b28 Linux 6.4-rc2
HEAD is now at c9c3395d5e3d Linux 6.2
$git rebase master
Successfully rebased and updated detached HEAD.
$git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
$git merge master
Already up to date.
Running menuconfig, there are no option for MIDI 2.0 / UMP,  though the Makefile shows 6.4-rc6 and the ump files are in the source tree.
Takashi Iwai June 18, 2023, 8:54 a.m. UTC | #14
On Sat, 17 Jun 2023 17:07:56 +0200,
Symbolic Debugger wrote:
> 
> An Attempt to replay the changes to 6.2 :
> starting with linux-next (On branch next-20230614) as master
> According to tag 6.4-rc2 the  commit for it is  f81fe2a4874338a1bfc599cae903a6101217b0a5
> # reset the  master to 6.4-rc2:
> $git reset --hard  581fe2a4874338a1bfc599cae903a6101217b0a5
> $git checkout v6.2
> Previous HEAD position was f1fcbaa18b28 Linux 6.4-rc2
> HEAD is now at c9c3395d5e3d Linux 6.2
> $git rebase master
> Successfully rebased and updated detached HEAD.
> $git checkout master
> Switched to branch 'master'
> Your branch is up to date with 'origin/master'.
> $git merge master
> Already up to date.
> Running menuconfig, there are no option for MIDI 2.0 / UMP,  though the Makefile shows 6.4-rc6 and the ump files are in the source tree.

Try the following:

% cd /somewhere/linux-next
% git reset --hard febdfa0e9c8a5d3a3d895245d1c294c26787daef
% git rebase --onto v6.2 v6.4-rc2

The commit febdfa is the topmost commit of MIDI 2.0 stuff.
This will plant the MIDI 2.0 stuff onto 6.2.

Alternatively:

% cd /somewhere/linux-stable
% git fetch /somewhere/linux-next febdfa0e9c8a5d3a3d895245d1c294c26787daef
% git reset --hard FETCH_HEAD
% git rebase --onto origin/linux-6.2.y v6.4-rc2

This will be onto the latest 6.2.y stable, instead.
If v6.4-rc2 tag isn't found, replace it with f1fcbaa18b28.


Takashi
Symbolic Debugger June 20, 2023, 1:29 p.m. UTC | #15
All kernel 6.2 files build successfully ! P.S. I saw a reference to you on the NAMM  booth. :-) Thank you so much !
Symbolic Debugger June 28, 2023, 6:52 a.m. UTC | #16
I have a few question on the implementation

1. As stated above:  So the driver may support multiple UMP Endpoints in theory, although most devices are supposed to have a single UMP EP that can contain up
to 16 groups -- which should be large enough.

I read (forgot where)  that Windows will  only supports 1 endpoint) . This would results in maximum 16 I/O ports when using one group terminal block per endpoint. Correct ? In that case manufacturers may not create  devices with multiple endpoints ... :-) ?

Per USB spec, One endpoint can support maximum 16 terminal blocks with each 16 groups so one endpoint in theory could support 256 (bi directional) groups and thus 512 ports (256 in/ 256 out)

2. If there is  one in and and out terminal  in an endpoint, then this will be presented as one in and one output port (in ALSA) ? Correct ?

3.  bGrpTrmBlkType: are 0x00, 0x01 and 0x02 all supported ?

4. At the MIDI device, should OUT endpoints be BULK,  and IN endpoints be INTERRUPT or BOTH BULK ? Page 21 of MIDI spec shows BULK for in and out but the descriptor example shows interrupt for IN. Page 19 states: MIDI Streaming Data Endpoints use bulk or interrupt transfers to exchange data with the Host

5. Are more than 1 Group Terminal Blocks supported by the driver for one endpoint ?

6. The current driver already uses the Group Terminal Blocks Descriptors Request ?
Takashi Iwai June 28, 2023, 11:12 a.m. UTC | #17
On Wed, 28 Jun 2023 08:52:25 +0200,
Symbolic Debugger wrote:
> 
> I have a few question on the implementation
> 
> 1. As stated above:  So the driver may support multiple UMP Endpoints in theory, although most devices are supposed to have a single UMP EP that can contain up
> to 16 groups -- which should be large enough.
> 
> I read (forgot where)  that Windows will  only supports 1 endpoint) . This would results in maximum 16 I/O ports when using one group terminal block per endpoint. Correct ? In that case manufacturers may not create  devices with multiple endpoints ... :-) ?

Yes, that's my point in the above.  It's not much expected that there
will be multiple (UMP) Endpoints on a single device.  In theory it's
still possible, and the Linux driver supports it, but for now, it's
supposed to be exceptional.  Other OS don't seem supporting multiple
EPs, in anyway.

> Per USB spec, One endpoint can support maximum 16 terminal blocks with each 16 groups so one endpoint in theory could support 256 (bi directional) groups and thus 512 ports (256 in/ 256 out)

One UMP EP can have up to 32 Function Blocks.  But the actual
limitation is rather the max number of UMP Groups (16) contained in a
single EP.

> 2. If there is  one in and and out terminal  in an endpoint, then this will be presented as one in and one output port (in ALSA) ? Correct ?

Not really, GTB or FB are merely meta data representing the
associations of UMP Groups on a UMP Endpoint.  The Groups included in
a FB can be even changed dynamically during the runtime, too.
The actual input and output entities are UMP Groups, which correspond
to the former MIDI ports.  GTB and FB indicate how those are tied.

BTW, a UMP Endpoint represents the bidirectional I/O by itself, so
it's a pair of USB Endpoints.

> 3.  bGrpTrmBlkType: are 0x00, 0x01 and 0x02 all supported ?

Yes.

> 4. At the MIDI device, should OUT endpoints be BULK,  and IN endpoints be INTERRUPT or BOTH BULK ? Page 21 of MIDI spec shows BULK for in and out but the descriptor example shows interrupt for IN. Page 19 states: MIDI Streaming Data Endpoints use bulk or interrupt transfers to exchange data with the Host

AFAIK, in most cases, INT is used for MIDI 2.0 USB Input Endpoint,
while BULK is used for USB Output Endpoint.  (On USB MIDI 1.0 spec,
both are BULK, although there have been a few vendor-specific
variants, too).  But the driver can work in ether way.  It just
depends on the USB descriptor.

> 5. Are more than 1 Group Terminal Blocks supported by the driver for one endpoint ?

Yes, and that's the very key point of MIDI 2.0.

> 6. The current driver already uses the Group Terminal Blocks Descriptors Request ?

Yes and no.  On Linux driver, GTBs are referred at first only to find
out a MIDI Endpoint pair.  Then, the driver tries to issue the new UMP
1.1 Stream message to obtain the UMP Endpoint and Function Block
information.  On older devices that don't under those UMP 1.1
messages, the driver falls back and uses GTBs as the primary source
for building a topology.


Takashi
Symbolic Debugger June 28, 2023, 11:32 a.m. UTC | #18
Thanks for the notes. I read the (USB) spec again page 27/28.  (well multiple times) and as I understood 1 endpoint has 1 or more multiple  Group Terminal Blocks for which GTB each has  1 to 16 groups (group = in/out or bi =  similar to one or two midi cables/ports)  per terminal block  The spec I have is from May 5th, 2020. i wonder how the driver get the Function Block information function blocks are not mentioned in the USB spec. Is there a a newer USB spec? if yes, it may make no sense to develop a device now if the descriptors and USB functions calls changed. Page 28 still refers to MIDI -CI protocol negotiation which already has been removed.  It's a bit confusing. Would have been better to first release the updated USB spec before releasing the updated MIDI specs.
Takashi Iwai June 28, 2023, 2:20 p.m. UTC | #19
On Wed, 28 Jun 2023 13:32:12 +0200,
Symbolic Debugger wrote:
> 
> Thanks for the notes. I read the (USB) spec again page 27/28.  (well multiple times) and as I understood 1 endpoint has 1 or more multiple  Group Terminal Blocks for which GTB each has  1 to 16 groups (group = in/out or bi =  similar to one or two midi cables/ports)  per terminal block  The spec I have is from May 5th, 2020. i wonder how the driver get the Function Block information function blocks are not mentioned in the USB spec. Is there a a newer USB spec? if yes, it may make no sense to develop a device now if the descriptors and USB functions calls changed. Page 28 still refers to MIDI -CI protocol negotiation which already has been removed.  It's a bit confusing. Would have been better to first release the updated USB spec before releasing the updated MIDI specs.

Basically a UMP EP can have up to 16 groups, and GTB indicates which
groups out of those can be managed together.  And for the old USB MIDI
2.0 spec, groups in multiple GTBs have to be unique; i.e. if GTB#1
contains the group#1, the group#1 can't be found in another GTBs.

OTOH, the new UMP 1.1 spec allows the shared groups by multiple
Function Blocks.  For explicitly disallowing this new (rather
confusing) behavior, "static block" flag was added in the FB info.
When this bit is set, the FB is fixed and doesn't overlap, so that
it's more or less compatible with GTB.

Note that Function Block is a new thing that was defined in UMP 1.1
spec.  Naturally it didn't exist in the old USB MIDI 2.0 spec of
year 2020.  But, the concept of Function Block (and implementation) is
rather about UMP, and it's independent from the transport layer; that
is, USB MIDI 2.0 spec still applies as is, and won't be updated soon,
AFAIK.  It's a matter of the driver which information is used as the
primary source: FB or GTB.  The device should provide both info, in
somehow compatible ways.


Takashi
Symbolic Debugger June 29, 2023, 2:03 a.m. UTC | #20
Thanks again for your time to reply . I think my coin has dropped :-)

1 .So basically, we have GTB in the device descriptor and the FB information is an UMP call to the device by the ALSA driver.  "The device should provide both info, in somehow compatible ways."  . The process would be [a]. driver gets USB device descriptors,  [b]. driver issues USB call to retrieve  USB GTB descriptors and then [c] driver issues UMP stream call to retrieve the function block information. (if N/A, driver falls back on the GTB information). This information should be consistent with the groups defined in the GTB.
2. When creating the device descriptors and GTB descriptors based on the 2020 USB 2.0 spec, it should work ?  Would those port show up in ALSA or can only be access via /dev/umpC*D*
3. w/o duplicates with 2 GTB's and for 32 groups, for example, it would be 1st GTB has group 1~16 and 2nd GTB 17~23  ?. A FB could use the groups from both GTB's for example Group1  and 17.
4. If two functions uses all 16 groups, that would use up all 32 FB's , correct ?
Takashi Iwai June 29, 2023, 6:40 a.m. UTC | #21
On Thu, 29 Jun 2023 04:03:47 +0200,
Symbolic Debugger wrote:
> 
> Thanks again for your time to reply . I think my coin has dropped :-)
> 
> 1 .So basically, we have GTB in the device descriptor and the FB information is an UMP call to the device by the ALSA driver.  "The device should provide both info, in somehow compatible ways."  . The process would be [a]. driver gets USB device descriptors,  [b]. driver issues USB call to retrieve  USB GTB descriptors and then [c] driver issues UMP stream call to retrieve the function block information. (if N/A, driver falls back on the GTB information). This information should be consistent with the groups defined in the GTB.

Correct.

> 2. When creating the device descriptors and GTB descriptors based on the 2020 USB 2.0 spec, it should work ?  Would those port show up in ALSA or can only be access via /dev/umpC*D*

Yes, there has been no change about the GTB itself; USB MIDI spec is
unchanged.  The recent MIDI 2.0 spec extended only UMP and MIDI-CI.

> 3. w/o duplicates with 2 GTB's and for 32 groups, for example, it would be 1st GTB has group 1~16 and 2nd GTB 17~23  ?. A FB could use the groups from both GTB's for example Group1  and 17.

First of all: you can't have more than 16 groups (per direction) on a
single EP.  It's a hard limitation.  So there can be no "Group 17".
(A UMP Group can be bidirectional.)

Imagine other way round: you have max 16 in and 16 out UMP Groups
where each Group has 16 channels, and GTB and FB just define how those
Groups are assigned to which actual I/O.  Some multiple Groups may
belong to the I/O for the same purpose, and in that case, those Groups
can be put into a single FB / GTB. 

> 4. If two functions uses all 16 groups, that would use up all 32 FB's , correct ?

If each FB contains one (single direction) Group and you have 16 in
and 16 out Groups, then yes, it'll be up to 32 FBs and GTBs, which is
the max number defined in the spec.  But a FB / GTB can contain
multiple Groups for the same purpose, so I guess taking all 32 FBs
would be rather a rare case.


Takashi
Symbolic Debugger June 29, 2023, 8:38 a.m. UTC | #22
Thanks again. Its getting much clearer now. To summarize:

[a] more than 1 Group Terminal Blocks are supported by the driver for one endpoint, but  [b] you can't have more than 16 groups (per direction) on a single EP.  and [c] if devices (mainly due to Windows)  only support 1 EP, that would mean when using two GTB for 16 groups,  one device cannot go beyond the 16 group limit. That would mean  - in a rare corner case - to design  ay a USB UMP (MIDI 1.0) interface that has legacy DIN I/O it can't go beyond 16 in and 16 OUT  DIN connectors.  

Perhaps a logical use for multiple GTB is to use one GTB per function, but on the others hand designers would probably won't take all that hassle if that if they can do with one GTB for all the functions, and mostly devices have two functions, one for voice data an one for firmware updates or other non-voice purposes.
Symbolic Debugger July 3, 2023, 10:15 a.m. UTC | #23
I wish to program (C) against the new ALSA drivers. Understandably the current alsa-lib one is for the current kernel (up to 6.4) but since I have the kernel installed, I don't have the .h and .so files and distro's may  include the packages  (libasound) even later. Is there a interim library available before the kernel and distro's are updated ?
Takashi Iwai July 3, 2023, 10:19 a.m. UTC | #24
On Mon, 03 Jul 2023 12:15:59 +0200,
Symbolic Debugger wrote:
> 
> I wish to program (C) against the new ALSA drivers. Understandably the current alsa-lib one is for the current kernel (up to 6.4) but since I have the kernel installed, I don't have the .h and .so files and distro's may  include the packages  (libasound) even later. Is there a interim library available before the kernel and distro's are updated ?

The build of alsa-lib doesn't rely on the kernel headers installed on
your system, as it has its own copies in the tree.  You just need to
update alsa-lib from the latest git version.


Takashi
Symbolic Debugger July 3, 2023, 11:25 a.m. UTC | #25
That's what I thought and checked, but did not see newfile, but now I do, Perhaps I checked a wrong repo. I pulled the latest repo, compiled (gitcompile) but it did not generate .so but it reports lot of .lo files. I wish not to overwrite the current libasound.so., so should it be :  make install with  --libdir=<my directory> to generate the .so files ?
Takashi Iwai July 3, 2023, 12:09 p.m. UTC | #26
On Mon, 03 Jul 2023 13:25:14 +0200,
Symbolic Debugger wrote:
> 
> That's what I thought and checked, but did not see newfile, but now I do, Perhaps I checked a wrong repo. I pulled the latest repo, compiled (gitcompile) but it did not generate .so but it reports lot of .lo files. I wish not to overwrite the current libasound.so., so should it be :  make install with  --libdir=<my directory> to generate the .so files ?

You can try to install it to a temporary directory specified via
DESTDIR variable as a test.  Also, the libasound.so.2.0.0 can be found
under src/.libs directory after the build.  You can simply copy that,
too.

But, for general build issues, better to ask your distro.  Someone
might have already a package built from the git repo, too.


Takashi
Symbolic Debugger July 3, 2023, 12:54 p.m. UTC | #27
Great !  Found the files. Thanks so much. BTW found the discrepancy. I downloaded the 1.2.9 alsa-lib (tar) files from the alsa website which did not have ump files as they do in the git 1.2.9 repo. I found this https://packages.ubuntu.com/search?keywords=asound  Seems libasound2-dev  is based on 1.2.9  but is for the next distro release (23.10) . Strangely, in the file list there are no ump files.
Takashi Iwai July 3, 2023, 1:01 p.m. UTC | #28
On Mon, 03 Jul 2023 14:54:16 +0200,
Symbolic Debugger wrote:
> 
> Great !  Found the files. Thanks so much. BTW found the discrepancy. I downloaded the 1.2.9 alsa-lib (tar) files from the alsa website which did not have ump files as they do in the git 1.2.9 repo. I found this https://packages.ubuntu.com/search?keywords=asound  Seems libasound2-dev  is based on 1.2.9  but is for the next distro release (23.10) . Strangely, in the file list there are no ump files.

1.2.9 is the already released one.  The UMP support *will* be included
in 1.2.10, once when released.  The git version is a bleeding edge
code, that is, would-be-1.2.10.


Takashi
Symbolic Debugger July 3, 2023, 1:53 p.m. UTC | #29
Thank you much. I should  have everything now to start building.
Symbolic Debugger July 12, 2023, 1:26 p.m. UTC | #30
A question about the implementation of notification messages (name, endpoint and function blocks)

The spec defines that these notification only get sent upon receiving a Discovery message. 

Does this mean that the ALSA driver will poll at specific intervals to send a discover message or  can the device send a notification even without a discovery message from the ALSA driver ? I could imagine a function block info / name, or endpoint info/ name or endpoint info change (i.e when the device changes the number of function block)
Takashi Iwai July 12, 2023, 1:58 p.m. UTC | #31
On Wed, 12 Jul 2023 15:26:15 +0200,
Symbolic Debugger wrote:
> 
> A question about the implementation of notification messages (name, endpoint and function blocks)
> 
> The spec defines that these notification only get sent upon receiving a Discovery message. 
> 
> Does this mean that the ALSA driver will poll at specific intervals to send a discover message or  can the device send a notification even without a discovery message from the ALSA driver ? I could imagine a function block info / name, or endpoint info/ name or endpoint info change (i.e when the device changes the number of function block)

It's handled in ALSA UMP core code.  It doesn't poll but just
interprets each incoming UMP messages and responds to it (e.g. when a
notification comes from the device, ALSA core will update the
information accordingly to be visible to user-space).

The change of FB info is indeed allowed by the device, AFAIK.  And,
this can notify via the corresponding UMP Stream messages.  For
example, reassigning UMP Groups in a FB is a valid scenario, and this
will be informed via UMP Stream messages.  For the FBs that will never
change Groups, there is a "static blocks" flag (which was quite
recently introduced).  I guess most of devices mark this, as it's
compatible with the former MIDI 2.0 USB devices.

BTW, the USB MIDI 2.0 gadget function driver is under development.
It's almost ready, and my plan is to submit likely for 6.6 kernel
(that is, in the next week or so).  You can find the patches in
topic/midi20-gadget branch of my sound.git tree.


Takashi