OpenBSD Journal

g2k14: Paul Irofti on the long road to octhci(4)

Contributed by tbert on from the USB-cookery-for-one dept.

I came to the hackathon with a single goal: working on the driver for the USB host controller interface found on the octeon machines.

I knew mpi@ would attend the event so that was a big plus. That meant that I could always reach him and bug him about how the OpenBSD USB infrastructure works and what's expected of the octhci(4) driver in different scenarios. Which, as I expected, ended-up being quite often.

I was pleasantly surprised when jasper@ asked me to share the serial to my DSR500 machine so that he could work on improving the boot(8) program that he started at t2k13. We had a lot of fun poking and discussing the different octeon issues that we ran into during the entire hackathon and people started referring to us as the octeon-team which was nice.

Things started moving once I managed to put together and understand the different logic and taxonomy between the OpenBSD's USB layer, the Cavium SDK and the actual USB 2.0 specification.

And so, I was confident enough to ask miod@ for permission to commit a work in progress driver. Now this stub of a driver was very powerful in that it managed to fry umass(4) devices immediately! So I made sure that it wasn't enabled by default and that the interrupt routine was disabled.

The next step was to add proper bus and hub routines that allowed the root hub to attach without a panic. Which was kind of nice as the dmesg(8) grew a bit:

octhci0 at iobus0 irq 56: core version 2 pass 3.5
usb0 at octhci0: USB revision 2.0
uhub0 at usb0 " octHCI root hub" rev 2.00/1.00 addr 1
uhub0: cannot open interrupt pipe
usb0: root device is not a hub

Afterwards I moved on to fixing the attach errors by adding proper root hub interrupt routines and filling in more bits and pieces in the HCI interrupt. That allowed me to enable the HCI interrupt which improved things a bit:

cthci0 at iobus0 irq 56: core version 2 pass 3.5
usb0 at octhci0: USB revision 2.0
uhub0 at usb0 " octHCI root hub" rev 2.00/1.00 addr 1

I made further progress by slowly filling in the controller-specific bits from the hub routines. That meant providing proper hub descriptors, getting and setting port features and clearing USB requests.

This lead to a build-up of immense confidence that in turn allowed me to convince myself that the time for a new device connection test was in-place.

The excitement was high. mpi@ joined my table and provided me with a YubiKey device to test with. But that didn't actually happen as he quickly changed his mind in fear of the Great USB Frying God and so brought over in exchange some old .vantronix USB sticks that he was more willing to see destroyed than the former YubiKey.

With trembling hands I connect the device and... the machine froze! I pulled it out and quickly connected it to my laptop to see if it still worked. It did! I was so happy!

I quickly found the cause of the freeze and fixed it: the host port interrupt flag was not cleared by the HCI interrupt routine so that lead to an interrupt storm.

Clearing the interrupt put the machine in the same state as before I started hacking on this driver: USB device connections had no effect (-:

Well that's not entirely true because now the kernel was becoming aware of USB events and knew how to properly treat some of them. This also meant that I could plug and unplug devices at will and test without fear of loss!

Following that, I started relaxing some overly-paranoid checks that I treated with immediate panics when true. They were put there since the dark-ages of the frying sticks and were actually wrong.

I added more event handling in the interrupt routines along with proper acknowledgment. I also started keeping track of port connections and port resets so that I can notify the upstream USB layer when connection status changed and when port resets were done.

I'm currently working on getting device control and transfer pipes rolling that will hopefully lead to a successful device attach.

Developments really sped up once device connections started working but unfortunately the hackathon came to and end.

The Ljulbjana hackathon was a great event that allowed me to accomplish and learn a lot for which I would like to thank Mitja (our awesome organizer), the OpenBSD Foundation and Theo de Raadt for their efforts of putting all of this together!

(Comments are closed)

  1. By Cabal (Cabal) Not Cabal on

    I'm really excited about upcoming Octeon work. For those interested in trying one out cheaply, you can't do much better than this:

    And current status:

    1. By Bruno Bigras ( on

      > I'm really excited about upcoming Octeon work. For those interested in trying one out cheaply, you can't do much better than this:

      On the status page it seems the ERLite only works when booting with NFS. Will it be eventually able to boot without NFS? By flashing it I guess (I didn't see an SD card port in the specs).

  2. By Anonymous Coward ( on

    Fry USB devices by plug them in? How in the hell can that be done?


Copyright © - Daniel Hartmeier. All rights reserved. Articles and comments are copyright their respective authors, submission implies license to publish on this web site. Contents of the archive prior to as well as images and HTML templates were copied from the fabulous original with Jose's and Jim's kind permission. This journal runs as CGI with httpd(8) on OpenBSD, the source code is BSD licensed. undeadly \Un*dead"ly\, a. Not subject to death; immortal. [Obs.]