NetBSD Problem Report #32567
From www@netbsd.org Thu Jan 19 00:40:08 2006
Return-Path: <www@netbsd.org>
Received: by narn.netbsd.org (Postfix, from userid 31301)
id 11E3463BA4E; Thu, 19 Jan 2006 00:40:08 +0000 (UTC)
Message-Id: <20060119004008.11E3463BA4E@narn.netbsd.org>
Date: Thu, 19 Jan 2006 00:40:08 +0000 (UTC)
From: nbgnats@anastigmatix.net
Reply-To: nbgnats@anastigmatix.net
To: gnats-bugs@netbsd.org
Subject: umidi(4) inconsistent treatment of cable number
X-Send-Pr-Version: www-1.0
>Number: 32567
>Category: kern
>Synopsis: umidi(4) inconsistent treatment of cable number
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: chap
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Jan 19 00:45:01 +0000 2006
>Closed-Date: Thu Sep 14 17:01:25 +0000 2006
>Last-Modified: Thu Sep 14 17:01:25 +0000 2006
>Originator: Chapman Flack
>Release: 2.0
>Organization:
>Environment:
NetBSD lundestad.anastigmatix.net 2.0 NetBSD 2.0 (lundestad) #86: Wed Jan 18 15:42:22 EST 2006 xxx@xxx:/usr/src/sys/arch/i386/compile/lundestad i386
>Description:
A USB MIDI device will support one or more USB 'endpoints' and an endpoint
can support up to sixteen 'jacks' each representing an independent MIDI
message stream. Messages for the jacks that share a common endpoint are
multiplexed by encapsulating them in packets that include a 4-bit Cable
Number (CN) identifying the jack, sending the packets on the common
endpoint, and demultiplexing them at the other end.
It should be clear from this discussion (16 jacks per endpoint, 4-bit
cable number) as well as the USB Device Class Definition for MIDI Devices,
section 4, that the CN is a per-endpoint identifier, and that a particular
jack is fully identified by <endpoint, CN on that endpoint>. However, the
code in umidi.c(alloc_all_jacks) currently assigns CNs in a global
sequence for the whole device, so that jacks on endpoints beyond the
first have cable numbers beginning above zero. On the other hand, in_intr
in the same file clearly assumes the CN is per endpoint, using it to
index a per-endpoint array of jacks, which could be an out of bounds index
in some cases given the way the CN is assigned.
Making matters murkier, there do seem to be nonstandard MIDI devices
that actually do expect a single global sequence of CNs--obviously
such devices will not have more than 16 jacks total--and so for those
devices the current behavior should be retained (but in_intr fixed
to avoid the indexing error). I don't have a wide variety of such
devices to test to see how prevalent that is, but because that is the
way the code has worked so far, to change it would probably break
support for some devices that now work.
So, I have introduced two complementary quirks, CN_SEQ_GLOBAL and
CN_SEQ_PER_EP. They are mutually exclusive and currently the default
if neither is given will be CN_SEQ_GLOBAL (the current behavior). The
point of adding two quirks for the same binary property is so either
behavior can be specified explicitly, which opens a path to later
changing the default to PER_EP without the need for a flag day.
in_intr is fixed to work correctly with either behavior (and will
report suspicious errors with a suggestion to check the CN SEQ quirk).
>How-To-Repeat:
I haven't actually seen a device that doesn't work on account of this
problem, but the inconsistency (and the fact that the array index in
in_intr would be out of bounds in some circumstances as a result) is
clear by inspection.
>Fix:
patch: http://www.anastigmatix.net/cvsweb.cgi/NetBSD/umidicn.pat
Patch is to 2.0 source after application of kern/32441 and 32442 patches.
CVS activity of the affected files has been very low so adapting to head
revisions should be easy (but 2.0 is what I've tested on).
>Release-Note:
>Audit-Trail:
From: Chapman Flack <nbgnats@anastigmatix.net>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/32567 umidi cable number
Date: Fri, 20 Jan 2006 08:49:24 -0500
hmm ... belay that patch for a moment ... this is more complicated yet.
There exist devices that require a particular assignment of cable
numbers, such as { 1, 3 } on endpoint 2 and { 2, 4 } on endpoint 4,
which will not match either general scheme. A CN_FIXED quirk type that
explicitly gives the mapping will be needed. I am working on updating
the patch.
My comments about array bounds were (taken literally) off base, as the
array has a fixed size of 16 so any CN will be a legal index; taken
broadly, they were still on the mark because alloc_all_jacks places the
jacks in the first consecutive slots of the array, not the slots
corresponding to their CNs. But just putting the jacks in the right slots
would be an easier fix than the cn_base field I added, and would have
the advantage of being able to cover the CN_FIXED case, which the cn_base
approach cannot.
From: Chapman Flack <nbgnats@anastigmatix.net>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/32567 umidi(4) cable numbers
Date: Sat, 21 Jan 2006 13:00:03 -0500
Updated the patch at the URL above. Now adds a UMQ_TYPE_CN_FIXED
quirk for devices that require any peculiar assignment of cable
numbers different from CN_SEQ_GLOBAL or CN_SEQ_PER_EP. But such
peculiar cable numbering could lead to a weird correspondence
between the auto-assigned rmidi unit numbers and the device's
physical ports or blinkenlights, so also adds a UMQ_TYPE_MD_FIXED
quirk to allow that mapping to be specified explicitly as well.
Interesting how I discovered the original CN assignments for
Midisport 2x4 were wrong: it has two endpoints (id 2 and 4)
and four actual ports (CN 0, 1, 2, and 3) and was originally
quirk'd to put CNs 0,1 on ep 2 and 2,3 on ep 4. It /worked/,
only it was possible on CNs 1 and 2 to achieve (apparent) data
rates much higher than the MIDI spec. Turns out the device
will accept data for any of the 4 CNs on either of the 2 eps,
but flow control only works on ep 2 for CN 0 and 2, and only
on ep 4 for 1 and 3, so that's what the assignment has to be.
There was no way to notice the problem without the patch for
kern/32588 because there was no way to achieve, much less
exceed, the actual MIDI data rate.
The moral is, in adding support for a new USB MIDI device, after
everything seems to be working, it should probably be standard
practice to do a data rate test (as shown in kern/32588) and
follow up any suspiciously high results - it may be that some
reshuffling of CN/ep assignments is necessary for flow control
to work and avoid dropped data.
Responsible-Changed-From-To: kern-bug-people->chap
Responsible-Changed-By: chap@netbsd.org
Responsible-Changed-When: Thu, 14 Sep 2006 17:01:25 +0000
Responsible-Changed-Why:
Made the changes.
State-Changed-From-To: open->closed
State-Changed-By: chap@netbsd.org
State-Changed-When: Thu, 14 Sep 2006 17:01:25 +0000
State-Changed-Why:
Addressed in chap-midi branch merged in June.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.