USB/Guide

This USB guide helps users setup and configure various USB devices on Gentoo systems.

What is USB?
USB stands for Universal Serial Bus which is an external interface standard that enables communication between computers and various peripherals. Some of the most commonly used USB devices are keyboards, mice, pen drives, digital cameras, external CD and DVD writers, printers, MP3 players, smart phones, and biometric devices.

There are currently three versions of USB in use, USB 2.0, USB 3.0, and USB 3.1. Since USB has always been backward compatible with previous versions, USB 2.0 is backwards compatible with USB 1.1. Likewise USB 3.0 and 3.1 can work with versions 2.0 and 1.1. The latest USB devices are typically USB 3.0 compatible, although some motherboards still include USB 2.0. USB 2.0 supports a maximum data transmission speed of 480 Mbit/s or 60 MB/s, 3.0 can transfer at a rate of 5.0 Gbit/s or 625 MB/s, and 3.1 tops out at a whopping 10.0 Gbit/s or 1.25 GB/s. Another advantage with USB is that the devices are all hot-pluggable, which means the system does not need a restart in order for the devices that have been plugged in to work.

A technical perspective
Before the exact configuration options in the kernel, it would be apt to look at USB in a little more detail. For readers in a hurry or want to skip this section, please go to the kernel configuration section.

A USB system has a host controller, hubs, a root hub amongst others and can support up to 127 USB devices including the hubs. The host controller is nothing but the hardware interface between the USB device and the operating system. There are a couple of HCIs (Host Controller Interfaces) in use today. They are the OHCI (Open HCI) by Compaq, UHCI (Universal HCI) and EHCI (Enhanced HCI) which are both from Intel, and xHCI (eXtensible Host Controller Interface). The OHCI/UHCI are the two industry standard USB 1.1 interfaces whereas EHCI is for USB 2.0 and xHCI is compatible with all of the previously mentioned interfaces including USB 3.0.

The hardware vendor provides an interface for the programmer that allows the system to interact with the hardware and this is called the HCD or Host Controller Device. It is through this HCD that the device interacts with the system software. The following diagram should make things easier to comprehend.

A USB device can either use a custom driver or use one already present in the system and this is based on the concept of a device class. This means that if a device belongs to a certain class, then other devices belonging to the same class can make use of the same device driver. Some of these classes are the USB HID (Human Interface Devices) class which covers input devices like keyboards and mice, the USB Mass Storage devices class which covers devices like pen drives, digital cameras, audio players etc and the USB CDC (Communication Devices Class) which essentially covers USB modems and similar devices.

What is on the machine?
It is very simple to find out whether the machine in question has USB 3.0 support. The lspci command is perfect for this purpose.

Example for a USB 1.1 compliant system (not the UHCI in the output):

A system that is USB 2.0 compliant, note the EHCI and UHCI:

So using the lspci command it is easy to determine if the system supports USB 2.0, or 3.0. This is useful for the section to come so that corresponding options can be correctly set in the kernel.

Getting the kernel
First emerge the kernel sources of your choice. Here we'll use. For more information on the various kernel sources available on Portage, please look up the Gentoo Linux Kernel Guide.

Now, lets get on with the task of configuring the kernel.

Config options for the kernel
Now we will look at some of the options we will have to enable in the kernel to ensure proper USB support for our devices.

If you have a USB keyboard, mouse, joystick, or any other input device, you need to enable HID support. Go back one level to "Device drivers" and enable HID support as shown:

Now that your options are set, you can (re)compile the kernel and USB support should be functional once you reboot into the new kernel.

dmesg is your friend!
In this section, we'll see how the system responds to various USB devices. We'll start by plugging in a USB 512 MB Memory Stick/Pen Drive. You could use some other similar mass storage device. We will primarily use  to see what is happening and how the system responds to the device.

Plug in Memory Stick into available USB port and then...

Once the device is connected and mounted, you can access it like a normal hard disk. Usual operations like,  ,  , etc work fine. You could also create a filesystem on the USB stick/format it.

How would a USB mouse show up in case you had one? It will show up as an HID device.

Another nifty command you can use to see the status of your USB ports is lsusb. This is part of and will be covered in the next chapter.

Nifty tools
So far we've seen how much support exists on the kernel and system side for USB on Linux. Now take a peek into what kind of support is provided by Gentoo for USB in the userspace.

One of the most useful tools around is lsusb. This lists all the USB devices connected to the system. Installing it is a breeze:

Once installed, run lsusb to get simple info on the USB devices attached to the machine. Like the lspci command, lsusb requires root privileges to execute. Use the root account or sudo to run this utility.}}

For those who love to see lots of information run lsusb</tt> with the  option. Another good option is that lsusb</tt> dumps the current physical USB hierarchy as a tree and thus makes it easier to understand the exact device map. The command is lsusb -t</tt>. For example:

You can easily correlate the outputs of lsusb</tt> and lsusb -t</tt>, which helps debugging as well as understanding how USB works.

External resources
The following documents are highly technical but truly interesting:


 * The Official USB Website
 * The USB FAQ
 * Compaq's OHCI Standard
 * Intel's UHCI Standard
 * Intel's EHCI Standard