9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: C H Forsyth <forsyth@vitanuova.com>
To: 9fans@cse.psu.edu
Subject: Re: usbd - revision (Was: [9fans] USB developments)
Date: Thu, 15 Jan 2004 18:01:41 +0000	[thread overview]
Message-ID: <eba7a85ba411e47adb5e556205d3ab5a@vitanuova.com> (raw)
In-Reply-To: <20040115144342.G25947@cackle.proxima.alt.za>

>> i therefore deliberately put enumeration outside the kernel because it is (potentially)
>> non-trivial and recursive (so is PCI enumeration but it has
>> rather less to do, placing less of a strain on KSTACK).
>>
>But no more than seven deep, or is that five?  Surely we can cope?
>Much more importantly, how complex is enumeration as such?  In my
>extremely limited understanding, it merely needs to return (assign,
>in fact) the ID of the device, its type and whether it connected
>or disconnected.  And, no, I'm not sure :-)  I'm asking.  Worse,
>I'm hoping.  But of course I can "just try it".

PCI enumeration would probably become more complex
for similar reasons when hot-swapping is possible.

i'll say a bit more about the original intention, and which parts i now dislike.

i observed that the linux and freebsd (and one other i can't mention)
usb implementations were rather complex.  much of that was related
to insisting on enumerating and configuring the devices in the kernel, and there was
quite a bit of non-trivial state.

in particular, to enumerate, you typically build a tree of devices.
if you're only enumerating in the kernel
(ie, assigning IDs) then a user-level program
will do configuration.  that needs to maintain a similar tree.
if a hub is removed, you need to delete chunks of substructure
but if both kernel and usbd are keeping a tree, they'll update
at different times (eg, kernel then usbd).  alternatively, they
can exchange data to try to keep things in sync, but then there's the potential for races.

furthermore, for the purposes of IO through the kernel, the tree structure is
irrelevant, since the ID space is actually flat and only endpoints within
devices matter.

it therefore seemed more straightforward to have the user process build the only
copy of the tree (which really is needed for enumeration and hot-plugging/unplugging)
and maintain it.  it then tells the kernel to enable devices.
the kernel provides files it can read to see the status of the root hub.
it monitors the state of individual hubs itself, using a process.
(ie, usbd is the class/device-specific manager for hubs.)
it's easy for usbd to use libthread, and do quite a bit of potentially
messy error handling that again i thought would be painful in the kernel.

a device-specific device managing process can do device-specific
configuration including parsing complex structures like the HID,
and it enables endpoints, within the given device directory.

the kernel needs to manage only structures for devices and endpoints
(which believe me are complex enough), and it does that in response to
instructions from user-mode programs.  usbd is in control.

i was broadly happy with the kernel/user split, and
the overall structure.  the kernel device is essentially
an IO multiplexor and i think that's about right.  the kernel doesn't
need to know about fancy hub trees or HID descriptors,
and that also seems good to me.  (for mouse and keyboard there
are or were special boot-time modes one could use before usbd could run.)
(in fact, usbd could probably devise/check the USB IO schedule too.)

at the time i wrote it five or six years ago (!), i had trouble finding
USB devices that kept to the spec--or even correct PIIXn implementations--
and decided to do more urgent things.  that's one reason that i
never supported iso mode (someone else did that and did a lot
of work on the driver and usbd).

had i realised that i wouldn't really get back to it, i'd have made several
more passes over it then.  for instance, when i first wrote it, qio.c didn't exist in Plan 9,
and i used Stream Blocks instead.  i was never very happy with
the amount of code in the driver overall, and it was ugly.
i did have a quick go at putting Queues in properly but didn't complete it.

i was much less happy with the name space.   i think it was right
that it's flat, an array of devices (rather than attempting to mimic the connection hierarchy
which seemed an irrelevant physical detail).   the naming within
the directories is fussy, though, and the use of physical
names (device/endpoint) to access logical things such as printer
or ether is troublesome.  i thought of allowing a logical name to be created
below usb, to refer to an endpoint or endpoints,
but not having tried it, i don't know whether that would be better.
sometimes a device presents one endpoint for reading and
one for writing, but interfaces such as ethermedium expect
a single name.   there are other peculiar cases.



  reply	other threads:[~2004-01-15 18:01 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-15  6:16 [9fans] USB developments Lucio De Re
2004-01-15  8:23 ` Fco.J.Ballesteros
2004-01-15  8:42   ` Lucio De Re
2004-01-15  9:13     ` Fco.J.Ballesteros
2004-01-15  9:17       ` Fco.J.Ballesteros
2004-01-15 10:05       ` Lucio De Re
2004-01-15 10:23         ` Fco.J.Ballesteros
2004-01-15 13:02         ` Lucio De Re
2004-01-15 14:05           ` Richard Miller
2004-01-15 14:44             ` Lucio De Re
2004-01-15 14:56               ` Fco.J.Ballesteros
2004-01-15 15:20                 ` Lucio De Re
2004-01-15 15:41                   ` Fco.J.Ballesteros
2004-01-15 14:53             ` Fco.J.Ballesteros
2004-01-15 21:25             ` Dan Cross
2004-01-15 10:30       ` usbd - revision (Was: [9fans] USB developments) Lucio De Re
2004-01-15 10:46         ` Fco.J.Ballesteros
2004-01-15 11:47           ` Lucio De Re
2004-01-15 12:11             ` Charles Forsyth
2004-01-15 12:43               ` Lucio De Re
2004-01-15 18:01                 ` C H Forsyth [this message]
2004-01-15 19:10                   ` Lucio De Re
2004-01-15 20:24                     ` Charles Forsyth
2004-01-15 21:00                       ` Micah Stetson
2004-01-16  6:18                       ` Lucio De Re
2004-01-16  7:34                     ` Fco.J.Ballesteros
2004-01-16  7:38                     ` Fco.J.Ballesteros
2004-01-16  7:59                       ` Lucio De Re
2004-01-16 10:23                       ` Bruce Ellis
2004-01-16 10:32                         ` Lucio De Re
2004-01-16 10:39                           ` boyd, rounin
2004-01-16 10:45                           ` Richard Miller
2004-01-16 11:41                             ` Bruce Ellis
2004-01-16 11:50                               ` rog
2004-01-15  9:07   ` [9fans] USB developments Charles Forsyth
2004-01-15  9:18     ` Fco.J.Ballesteros
2004-01-15 10:39     ` Lucio De Re
2004-01-15 10:48       ` Richard Miller
2004-01-15  9:10 ` Richard Miller
2004-01-15  9:14   ` Fco.J.Ballesteros
2004-01-16  9:59 ` boyd, rounin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eba7a85ba411e47adb5e556205d3ab5a@vitanuova.com \
    --to=forsyth@vitanuova.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).