Peios Learn
Documentation

Peios

Peios Peios Kernel Universal Directory Project

Developer Tools

Trail Acta Provium clackatoo CAF GCSL Pekit

Applications

Framewright

Standards and Conventions

Standards and Conventions Peios Specifications
Peios Kernel

Device configuration

Single-page view · as markdown

btmrvl driver

Peios Kernel / Administration / System administration / Device configuration

All commands are used via debugfs interface.

Set/get driver configurations #

Path: /debug/btmrvl/config/

  • gpiogap=[n], hscfgcmd

    These commands are used to configure the host sleep parameters:: bit 8:0 -- Gap bit 16:8 -- GPIO

    where GPIO is the pin number of GPIO used to wake up the host. It could be any valid GPIO pin# (e.g. 0-7) or 0xff (SDIO interface wakeup will be used instead).

    where Gap is the gap in milli seconds between wakeup signal and wakeup event, or 0xff for special host sleep setting.

    Usage:

    # Use SDIO interface to wake up the host and set GAP to 0x80:
    echo 0xff80 > /debug/btmrvl/config/gpiogap
    echo 1 > /debug/btmrvl/config/hscfgcmd
    
    # Use GPIO pin #3 to wake up the host and set GAP to 0xff:
    echo 0x03ff >  /debug/btmrvl/config/gpiogap
    echo 1 > /debug/btmrvl/config/hscfgcmd
    
  • psmode=[n], pscmd

    These commands are used to enable/disable auto sleep mode

    where the option is:

    1       -- Enable auto sleep mode
    0       -- Disable auto sleep mode
    

    Usage:

    # Enable auto sleep mode
    echo 1 > /debug/btmrvl/config/psmode
    echo 1 > /debug/btmrvl/config/pscmd
    
    # Disable auto sleep mode
    echo 0 > /debug/btmrvl/config/psmode
    echo 1 > /debug/btmrvl/config/pscmd
    
  • hsmode=[n], hscmd

    These commands are used to enable host sleep or wake up firmware

    where the option is:

    1       -- Enable host sleep
    0       -- Wake up firmware
    

    Usage:

    # Enable host sleep
    echo 1 > /debug/btmrvl/config/hsmode
    echo 1 > /debug/btmrvl/config/hscmd
    
    # Wake up firmware
    echo 0 > /debug/btmrvl/config/hsmode
    echo 1 > /debug/btmrvl/config/hscmd
    

Get driver status #

Path: /debug/btmrvl/status/

Usage:

cat /debug/btmrvl/status/<args>

where the args are:

  • curpsmode

    This command displays current auto sleep status.

  • psstate

    This command display the power save state.

  • hsstate

    This command display the host sleep state.

  • txdnldrdy

    This command displays the value of Tx download ready flag.

Issuing a raw hci command #

Use hcitool to issue raw hci command, refer to hcitool manual

Usage:

Hcitool cmd <ogf> <ocf> [Parameters]

Interface Control Command:

hcitool cmd 0x3f 0x5b 0xf5 0x01 0x00    --Enable All interface
hcitool cmd 0x3f 0x5b 0xf5 0x01 0x01    --Enable Wlan interface
hcitool cmd 0x3f 0x5b 0xf5 0x01 0x02    --Enable BT interface
hcitool cmd 0x3f 0x5b 0xf5 0x00 0x00    --Disable All interface
hcitool cmd 0x3f 0x5b 0xf5 0x00 0x01    --Disable Wlan interface
hcitool cmd 0x3f 0x5b 0xf5 0x00 0x02    --Disable BT interface

SD8688 firmware #

Images:

  • /lib/firmware/sd8688_helper.bin

  • /lib/firmware/sd8688.bin

The images can be downloaded from:

git.infradead.org/users/dwmw2/linux-firmware.git/libertas/

Dell Remote BIOS Update driver (dell_rbu)

Peios Kernel / Administration / System administration / Device configuration

Purpose #

Document demonstrating the use of the Dell Remote BIOS Update driver for updating BIOS images on Dell servers and desktops.

Scope #

This document discusses the functionality of the rbu driver only. It does not cover the support needed from applications to enable the BIOS to update itself with the image downloaded in to the memory.

Overview #

This driver works with Dell OpenManage or Dell Update Packages for updating the BIOS on Dell servers (starting from servers sold since 1999), desktops and notebooks (starting from those sold in 2005).

Please go to http://support.dell.com register and you can find info on OpenManage and Dell Update packages (DUP).

Libsmbios can also be used to update BIOS on Dell systems go to https://linux.dell.com/libsmbios/ for details.

Dell_RBU driver supports BIOS update using the monolithic image and packetized image methods. In case of monolithic the driver allocates a contiguous chunk of physical pages having the BIOS image. In case of packetized the app using the driver breaks the image in to packets of fixed sizes and the driver would place each packet in contiguous physical memory. The driver also maintains a link list of packets for reading them back.

If the dell_rbu driver is unloaded all the allocated memory is freed.

The rbu driver needs to have an application (as mentioned above) which will inform the BIOS to enable the update in the next system reboot.

The user should not unload the rbu driver after downloading the BIOS image or updating.

The driver load creates the following directories under the /sys file system:

/sys/class/firmware/dell_rbu/loading
/sys/class/firmware/dell_rbu/data
/sys/devices/platform/dell_rbu/image_type
/sys/devices/platform/dell_rbu/data
/sys/devices/platform/dell_rbu/packet_size

The driver supports two types of update mechanism; monolithic and packetized. These update mechanism depends upon the BIOS currently running on the system. Most of the Dell systems support a monolithic update where the BIOS image is copied to a single contiguous block of physical memory.

In case of packet mechanism the single memory can be broken in smaller chunks of contiguous memory and the BIOS image is scattered in these packets.

By default the driver uses monolithic memory for the update type. This can be changed to packets during the driver load time by specifying the load parameter image_type=packet. This can also be changed later as below:

echo packet > /sys/devices/platform/dell_rbu/image_type

In packet update mode the packet size has to be given before any packets can be downloaded. It is done as below:

echo XXXX > /sys/devices/platform/dell_rbu/packet_size

In the packet update mechanism, the user needs to create a new file having packets of data arranged back to back. It can be done as follows: The user creates packets header, gets the chunk of the BIOS image and places it next to the packetheader; now, the packetheader + BIOS image chunk added together should match the specified packet_size. This makes one packet, the user needs to create more such packets out of the entire BIOS image file and then arrange all these packets back to back in to one single file.

This file is then copied to /sys/class/firmware/dell_rbu/data. Once this file gets to the driver, the driver extracts packet_size data from the file and spreads it across the physical memory in contiguous packet_sized space.

This method makes sure that all the packets get to the driver in a single operation.

In monolithic update the user simply get the BIOS image (.hdr file) and copies to the data file as is without any change to the BIOS image itself.

Do the steps below to download the BIOS image.

  1. echo 1 > /sys/class/firmware/dell_rbu/loading

  2. cp bios_image.hdr /sys/class/firmware/dell_rbu/data

  3. echo 0 > /sys/class/firmware/dell_rbu/loading

The /sys/class/firmware/dell_rbu/ entries will remain till the following is done.

echo -1 > /sys/class/firmware/dell_rbu/loading

Until this step is completed the driver cannot be unloaded.

Also echoing either mono, packet or init in to image_type will free up the memory allocated by the driver.

If a user by accident executes steps 1 and 3 above without executing step 2; it will make the /sys/class/firmware/dell_rbu/ entries disappear.

The entries can be recreated by doing the following:

echo init > /sys/devices/platform/dell_rbu/image_type

Note

echoing init in image_type does not change its original value.

Also the driver provides /sys/devices/platform/dell_rbu/data readonly file to read back the image downloaded.

Note

After updating the BIOS image a user mode application needs to execute code which sends the BIOS update request to the BIOS. So on the next reboot the BIOS knows about the new image downloaded and it updates itself. Also don't unload the rbu driver if the image has to be updated.

EDID

Peios Kernel / Administration / System administration / Device configuration

In the good old days when graphics parameters were configured explicitly in a file called xorg.conf, even broken hardware could be managed.

Today, with the advent of Kernel Mode Setting, a graphics board is either correctly working because all components follow the standards - or the computer is unusable, because the screen remains dark after booting or it displays the wrong area. Cases when this happens are:

  • The graphics board does not recognize the monitor.

  • The graphics board is unable to detect any EDID data.

  • The graphics board incorrectly forwards EDID data to the driver.

  • The monitor sends no or bogus EDID data.

  • A KVM sends its own EDID data instead of querying the connected monitor.

Adding the kernel parameter "nomodeset" helps in most cases, but causes restrictions later on.

As a remedy for such situations, the kernel configuration item CONFIG_DRM_LOAD_EDID_FIRMWARE was introduced. It allows to provide an individually prepared or corrected EDID data set in the /lib/firmware directory from where it is loaded via the firmware interface.

Hardware random number generators

Peios Kernel / Administration / System administration / Device configuration

Introduction #

The hw_random framework is software that makes use of a special hardware feature on your CPU or motherboard, a Random Number Generator (RNG). The software has two parts: a core providing the /dev/hwrng character device and its sysfs support, plus a hardware-specific driver that plugs into that core.

To make the most effective use of these mechanisms, you should download the support software as well. Download the latest version of the "rng-tools" package from:

https://github.com/nhorman/rng-tools

Those tools use /dev/hwrng to fill the kernel entropy pool, which is used internally and exported by the /dev/urandom and /dev/random special files.

Theory of operation #

CHARACTER DEVICE. Using the standard open() and read() system calls, you can read random data from the hardware RNG device. This data is NOT CHECKED by any fitness tests, and could potentially be bogus (if the hardware is faulty or has been tampered with). Data is only output if the hardware "has-data" flag is set, but nevertheless a security-conscious person would run fitness tests on the data before assuming it is truly random.

The rng-tools package uses such tests in "rngd", and lets you run them by hand with a "rngtest" utility.

/dev/hwrng is char device major 10, minor 183.

CLASS DEVICE. There is a /sys/class/misc/hw_random node with two unique attributes, "rng_available" and "rng_current". The "rng_available" attribute lists the hardware-specific drivers available, while "rng_current" lists the one which is currently connected to /dev/hwrng. If your system has more than one RNG available, you may change the one used by writing a name from the list in "rng_available" into "rng_current".


  • Hardware driver for Intel/AMD/VIA Random Number Generators (RNG)

    • Copyright 2000,2001 Jeff Garzik <jgarzik@pobox.com>

    • Copyright 2000,2001 Philipp Rumpf <prumpf@mandrakesoft.com>

About the Intel RNG hardware, from the firmware hub datasheet #

The Firmware Hub integrates a Random Number Generator (RNG) using thermal noise generated from inherently random quantum mechanical properties of silicon. When not generating new random bits the RNG circuitry will enter a low power state. Intel will provide a binary software driver to give third party software access to our RNG for use as a security feature. At this time, the RNG is only to be used with a system in an OS-present state.

Intel RNG Driver notes #

FIXME: support poll(2)

Note

request_mem_region was removed, for three reasons:

  1. Only one RNG is supported by this driver;

  2. The location used by the RNG is a fixed location in MMIO-addressable memory;

  3. users with properly working BIOS e820 handling will always have the region in which the RNG is located reserved, so request_mem_region calls always fail for proper setups. However, for people who use mem=XX, BIOS e820 information is not in /proc/iomem, and request_mem_region(RNG_ADDR) can succeed.

Driver details #

  • Based on:

    Intel 82802AB/82802AC Firmware Hub (FWH) Datasheet May 1999 Order Number: 290658-002 R

  • Intel 82802 Firmware Hub:

    Random Number Generator Programmer's Reference Manual December 1999 Order Number: 298029-001 R

  • Intel 82802 Firmware HUB Random Number Generator Driver

    Copyright (c) 2000 Matt Sottek <msottek@quiknet.com>

Special thanks to Matt Sottek. I did the "guts", he did the "brains" and all the testing.

Parallel port LCD/Keypad Panel support

Peios Kernel / Administration / System administration / Device configuration

Some LCDs allow you to define up to 8 characters, mapped to ASCII characters 0 to 7. The escape code to define a new character is 'e[LG' followed by one digit from 0 to 7, representing the character number, and up to 8 couples of hex digits terminated by a semi-colon (';'). Each couple of digits represents a line, with 1-bits for each illuminated pixel with LSB on the right. Lines are numbered from the top of the character to the bottom. On a 5x7 matrix, only the 5 lower bits of the 7 first bytes are used for each character. If the string is incomplete, only complete lines will be redefined. Here are some examples:

printf "\e[LG0010101050D1F0C04;"  => 0 = [enter]
printf "\e[LG1040E1F0000000000;"  => 1 = [up]
printf "\e[LG2000000001F0E0400;"  => 2 = [down]
printf "\e[LG3040E1F001F0E0400;"  => 3 = [up-down]
printf "\e[LG40002060E1E0E0602;"  => 4 = [left]
printf "\e[LG500080C0E0F0E0C08;"  => 5 = [right]
printf "\e[LG60016051516141400;"  => 6 = "IP"

printf "\e[LG00103071F1F070301;"  => big speaker
printf "\e[LG00002061E1E060200;"  => small speaker

Willy

Parport

Peios Kernel / Administration / System administration / Device configuration

The parport code provides parallel-port support under Linux. This includes the ability to share one port between multiple device drivers.

You can pass parameters to the parport code to override its automatic detection of your hardware. This is particularly useful if you want to use IRQs, since in general these can't be autoprobed successfully. By default IRQs are not used even if they can be probed. This is because there are a lot of people using the same IRQ for their parallel port and a sound card or network card.

The parport code is split into two parts: generic (which deals with port-sharing) and architecture-dependent (which deals with actually using the port).

Parport as modules #

If you load the parport` code as a module, say:

# insmod parport

to load the generic parport code. You then must load the architecture-dependent code with (for example):

# insmod parport_pc io=0x3bc,0x378,0x278 irq=none,7,auto

to tell the parport code that you want three PC-style ports, one at 0x3bc with no IRQ, one at 0x378 using IRQ 7, and one at 0x278 with an auto-detected IRQ. Currently, PC-style (parport_pc), Sun bpp, Amiga, Atari, and MFC3 hardware is supported.

PCI parallel I/O card support comes from parport_pc. Base I/O addresses should not be specified for supported PCI cards since they are automatically detected.

modprobe #

If you use modprobe , you will find it useful to add lines as below to a configuration file in /etc/modprobe.d/ directory:

alias parport_lowlevel parport_pc
options parport_pc io=0x378,0x278 irq=7,auto

modprobe will load parport_pc (with the options io=0x378,0x278 irq=7,auto) whenever a parallel port device driver (such as lp) is loaded.

Note that these are example lines only! You shouldn't in general need to specify any options to parport_pc in order to be able to use a parallel port.

Parport probe [optional] #

In 2.2 kernels there was a module called parport_probe, which was used for collecting IEEE 1284 device ID information. This has now been enhanced and now lives with the IEEE 1284 support. When a parallel port is detected, the devices that are connected to it are analysed, and information is logged like this:

parport0: Printer, BJC-210 (Canon)

The probe information is available from files in /proc/sys/dev/parport/.

Parport linked into the kernel statically #

If you compile the parport code into the kernel, then you can use kernel boot parameters to get the same effect. Add something like the following to your LILO command line:

parport=0x3bc parport=0x378,7 parport=0x278,auto,nofifo

You can have many parport=... statements, one for each port you want to add. Adding parport=0 to the kernel command-line will disable parport support entirely. Adding parport=auto to the kernel command-line will make parport use any IRQ lines or DMA channels that it auto-detects.

Files in /proc #

If you have configured the /proc filesystem into your kernel, you will see a new directory entry: /proc/sys/dev/parport. In there will be a directory entry for each parallel port for which parport is configured. In each of those directories are a collection of files describing that parallel port.

The /proc/sys/dev/parport directory tree looks like:

parport
|-- default
|   |-- spintime
|   `-- timeslice
|-- parport0
|   |-- autoprobe
|   |-- autoprobe0
|   |-- autoprobe1
|   |-- autoprobe2
|   |-- autoprobe3
|   |-- devices
|   |   |-- active
|   |   `-- lp
|   |       `-- timeslice
|   |-- base-addr
|   |-- irq
|   |-- dma
|   |-- modes
|   `-- spintime
`-- parport1
|-- autoprobe
|-- autoprobe0
|-- autoprobe1
|-- autoprobe2
|-- autoprobe3
|-- devices
|   |-- active
|   `-- ppa
|       `-- timeslice
|-- base-addr
|-- irq
|-- dma
|-- modes
`-- spintime

File

Contents

devices/active

A list of the device drivers using that port. A "+" will appear by the name of the device currently using the port (it might not appear against any). The string "none" means that there are no device drivers using that port.

base-addr

Parallel port's base address, or addresses if the port has more than one in which case they are separated with tabs. These values might not have any sensible meaning for some ports.

irq

Parallel port's IRQ, or -1 if none is being used.

dma

Parallel port's DMA channel, or -1 if none is being used.

modes

Parallel port's hardware modes, comma-separated, meaning:

    • PCSPP

      PC-style SPP registers are available.

    • TRISTATE

      Port is bidirectional.

    • COMPAT

      Hardware acceleration for printers is available and will be used.

    • EPP

      Hardware acceleration for EPP protocol is available and will be used.

    • ECP

      Hardware acceleration for ECP protocol is available and will be used.

    • DMA

      DMA is available and will be used.

Note that the current implementation will only take advantage of COMPAT and ECP modes if it has an IRQ line to use.

autoprobe

Any IEEE-1284 device ID information that has been acquired from the (non-IEEE 1284.3) device.

autoprobe[0-3]

IEEE 1284 device ID information retrieved from daisy-chain devices that conform to IEEE 1284.3.

spintime

The number of microseconds to busy-loop while waiting for the peripheral to respond. You might find that adjusting this improves performance, depending on your peripherals. This is a port-wide setting, i.e. it applies to all devices on a particular port.

timeslice

The number of milliseconds that a device driver is allowed to keep a port claimed for. This is advisory, and driver can ignore it if it must.

default/*

The defaults for spintime and timeslice. When a new port is registered, it picks up the default spintime. When a new device is registered, it picks up the default timeslice.

Device drivers #

Once the parport code is initialised, you can attach device drivers to specific ports. Normally this happens automatically; if the lp driver is loaded it will create one lp device for each port found. You can override this, though, by using parameters either when you load the lp driver:

# insmod lp parport=0,2

or on the LILO command line:

lp=parport0 lp=parport2

Both the above examples would inform lp that you want /dev/lp0 to be the first parallel port, and /dev/lp1 to be the third parallel port, with no lp device associated with the second port (parport1). Note that this is different to the way older kernels worked; there used to be a static association between the I/O port address and the device name, so /dev/lp0 was always the port at 0x3bc. This is no longer the case - if you only have one port, it will default to being /dev/lp0, regardless of base address.

Also:

  • If you selected the IEEE 1284 support at compile time, you can say lp=auto on the kernel command line, and lp will create devices only for those ports that seem to have printers attached.

  • If you give PLIP the timid parameter, either with plip=timid on the command line, or with insmod plip timid=1 when using modules, it will avoid any ports that seem to be in use by other devices.

  • IRQ autoprobing works only for a few port types at the moment.

Reporting printer problems with parport #

If you are having problems printing, please go through these steps to try to narrow down where the problem area is.

When reporting problems with parport, really you need to give all of the messages that parport_pc spits out when it initialises. There are several code paths:

  • polling

  • interrupt-driven, protocol in software

  • interrupt-driven, protocol in hardware using PIO

  • interrupt-driven, protocol in hardware using DMA

The kernel messages that parport_pc logs give an indication of which code path is being used. (They could be a lot better actually..)

For normal printer protocol, having IEEE 1284 modes enabled or not should not make a difference.

To turn off the 'protocol in hardware' code paths, disable CONFIG_PARPORT_PC_FIFO. Note that when they are enabled they are not necessarily used; it depends on whether the hardware is available, enabled by the BIOS, and detected by the driver.

So, to start with, disable CONFIG_PARPORT_PC_FIFO, and load parport_pc with irq=none. See if printing works then. It really should, because this is the simplest code path.

If that works fine, try with io=0x378 irq=7 (adjust for your hardware), to make it use interrupt-driven in-software protocol.

If that works fine, then one of the hardware modes isn't working right. Enable CONFIG_FIFO (no, it isn't a module option, and yes, it should be), set the port to ECP mode in the BIOS and note the DMA channel, and try with:

io=0x378 irq=7 dma=none (for PIO)
io=0x378 irq=7 dma=3 (for DMA)

philb@gnu.org tim@cyberelk.net

Linux Plug and Play Documentation

Peios Kernel / Administration / System administration / Device configuration

Author: Adam Belay <ambx1@neo.rr.com>

Last updated: Oct. 16, 2002

Overview #

Plug and Play provides a means of detecting and setting resources for legacy or otherwise unconfigurable devices. The Linux Plug and Play Layer provides these services to compatible drivers.

The User Interface #

The Linux Plug and Play user interface provides a means to activate PnP devices for legacy and user level drivers that do not support Linux Plug and Play. The user interface is integrated into sysfs.

In addition to the standard sysfs file the following are created in each device's directory: - id - displays a list of support EISA IDs - options - displays possible resource configurations - resources - displays currently allocated resources and allows resource changes

activating a device #

# echo "auto" > resources

this will invoke the automatic resource config system to activate the device

manually activating a device #

# echo "manual <depnum> <mode>" > resources

<depnum> - the configuration number
<mode> - static or dynamic
         static = for next boot
         dynamic = now

disabling a device #

# echo "disable" > resources

EXAMPLE:

Suppose you need to activate the floppy disk controller.

  1. change to the proper directory, in my case it is /driver/bus/pnp/devices/00:0f:

    # cd /driver/bus/pnp/devices/00:0f
    # cat name
    PC standard floppy disk controller
    
  2. check if the device is already active:

    # cat resources
    DISABLED
    
  • Notice the string "DISABLED". This means the device is not active.
  1. check the device's possible configurations (optional):

    # cat options
    Dependent: 01 - Priority acceptable
        port 0x3f0-0x3f0, align 0x7, size 0x6, 16-bit address decoding
        port 0x3f7-0x3f7, align 0x0, size 0x1, 16-bit address decoding
        irq 6
        dma 2 8-bit compatible
    Dependent: 02 - Priority acceptable
        port 0x370-0x370, align 0x7, size 0x6, 16-bit address decoding
        port 0x377-0x377, align 0x0, size 0x1, 16-bit address decoding
        irq 6
        dma 2 8-bit compatible
    
  2. now activate the device:

    # echo "auto" > resources
    
  3. finally check if the device is active:

    # cat resources
    io 0x3f0-0x3f5
    io 0x3f7-0x3f7
    irq 6
    dma 2
    

also there are a series of kernel parameters:

pnp_reserve_irq=irq1[,irq2] ....
pnp_reserve_dma=dma1[,dma2] ....
pnp_reserve_io=io1,size1[,io2,size2] ....
pnp_reserve_mem=mem1,size1[,mem2,size2] ....

The Unified Plug and Play Layer #

All Plug and Play drivers, protocols, and services meet at a central location called the Plug and Play Layer. This layer is responsible for the exchange of information between PnP drivers and PnP protocols. Thus it automatically forwards commands to the proper protocol. This makes writing PnP drivers significantly easier.

The following functions are available from the Plug and Play Layer:

  • pnp_get_protocol

    increments the number of uses by one

  • pnp_put_protocol

    deincrements the number of uses by one

  • pnp_register_protocol

    use this to register a new PnP protocol

  • pnp_register_driver

    adds a PnP driver to the Plug and Play Layer

    this includes driver model integration returns zero for success or a negative error number for failure; count calls to the .add() method if you need to know how many devices bind to the driver

  • pnp_unregister_driver

    removes a PnP driver from the Plug and Play Layer

Plug and Play Protocols #

This section contains information for PnP protocol developers.

The following Protocols are currently available in the computing world:

    • PNPBIOS:

      used for system devices such as serial and parallel ports.

    • ISAPNP:

      provides PnP support for the ISA bus

    • ACPI:

      among its many uses, ACPI provides information about system level devices.

It is meant to replace the PNPBIOS. It is not currently supported by Linux Plug and Play but it is planned to be in the near future.

Requirements for a Linux PnP protocol: 1. the protocol must use EISA IDs 2. the protocol must inform the PnP Layer of a device's current configuration

  • the ability to set resources is optional but preferred.

The following are PnP protocol related functions:

  • pnp_add_device

    use this function to add a PnP device to the PnP layer

    only call this function when all wanted values are set in the pnp_dev structure

  • pnp_init_device

    call this to initialize the PnP structure

  • pnp_remove_device

    call this to remove a device from the Plug and Play Layer. it will fail if the device is still in use. automatically will free mem used by the device and related structures

  • pnp_add_id

    adds an EISA ID to the list of supported IDs for the specified device

For more information consult the source of a protocol such as /drivers/pnp/pnpbios/core.c.

Linux Plug and Play Drivers #

This section contains information for Linux PnP driver developers.

The New Way #

  1. first make a list of supported EISA IDS

    ex:

    static const struct pnp_id pnp_dev_table[] = {
            /* Standard LPT Printer Port */
            {.id = "PNP0400", .driver_data = 0},
            /* ECP Printer Port */
            {.id = "PNP0401", .driver_data = 0},
            {.id = ""}
    };
    

    Please note that the character 'X' can be used as a wild card in the function portion (last four characters).

    ex:

    /* Unknown PnP modems */
    {       "PNPCXXX",              UNKNOWN_DEV     },
    

    Supported PnP card IDs can optionally be defined. ex:

    static const struct pnp_id pnp_card_table[] = {
            {       "ANYDEVS",              0       },
            {       "",                     0       }
    };
    
  2. Optionally define probe and remove functions. It may make sense not to define these functions if the driver already has a reliable method of detecting the resources, such as the parport_pc driver.

    ex:

    static int
    serial_pnp_probe(struct pnp_dev * dev, const struct pnp_id *card_id, const
                    struct pnp_id *dev_id)
    {
    . . .
    

    ex:

    static void serial_pnp_remove(struct pnp_dev * dev)
    {
    . . .
    

    consult /drivers/serial/8250_pnp.c for more information.

  3. create a driver structure

    ex:

    static struct pnp_driver serial_pnp_driver = {
            .name           = "serial",
            .card_id_table  = pnp_card_table,
            .id_table       = pnp_dev_table,
            .probe          = serial_pnp_probe,
            .remove         = serial_pnp_remove,
    };
    
    • name and id_table cannot be NULL.
  4. register the driver

    ex:

    static int __init serial8250_pnp_init(void)
    {
            return pnp_register_driver(&serial_pnp_driver);
    }
    

The Old Way #

A series of compatibility functions have been created to make it easy to convert ISAPNP drivers. They should serve as a temporary solution only.

They are as follows:

struct pnp_dev *pnp_find_dev(struct pnp_card *card,
                             unsigned short vendor,
                             unsigned short function,
                             struct pnp_dev *from)

RapidIO Subsystem Guide

Peios Kernel / Administration / System administration / Device configuration

Author: Matt Porter

Introduction #

RapidIO is a high speed switched fabric interconnect with features aimed at the embedded market. RapidIO provides support for memory-mapped I/O as well as message-based transactions over the switched fabric network. RapidIO has a standardized discovery mechanism not unlike the PCI bus standard that allows simple detection of devices in a network.

This documentation is provided for developers intending to support RapidIO on new architectures, write new drivers, or to understand the subsystem internals.

Known Bugs and Limitations #

Bugs #

None. ;)

Limitations #

  1. Access/management of RapidIO memory regions is not supported

  2. Multiple host enumeration is not supported

RapidIO driver interface #

Drivers are provided a set of calls in order to interface with the subsystem to gather info on devices, request/map memory region resources, and manage mailboxes/doorbells.

Functions #

rio_local_read_config_32() #

int rio_local_read_config_32(struct rio_mport *port, u32 offset, u32 * data)

Read 32 bits from local configuration space

Parameters

  • struct rio_mport *port: Master port
  • u32 offset: Offset into local configuration space
  • u32 * data: Pointer to read data into

Description

Reads 32 bits of data from the specified offset within the local device's configuration space.

rio_local_write_config_32() #

int rio_local_write_config_32(struct rio_mport *port, u32 offset, u32 data)

Write 32 bits to local configuration space

Parameters

  • struct rio_mport *port: Master port
  • u32 offset: Offset into local configuration space
  • u32 data: Data to be written

Description

Writes 32 bits of data to the specified offset within the local device's configuration space.

rio_local_read_config_16() #

int rio_local_read_config_16(struct rio_mport *port, u32 offset, u16 * data)

Read 16 bits from local configuration space

Parameters

  • struct rio_mport *port: Master port
  • u32 offset: Offset into local configuration space
  • u16 * data: Pointer to read data into

Description

Reads 16 bits of data from the specified offset within the local device's configuration space.

rio_local_write_config_16() #

int rio_local_write_config_16(struct rio_mport *port, u32 offset, u16 data)

Write 16 bits to local configuration space

Parameters

  • struct rio_mport *port: Master port
  • u32 offset: Offset into local configuration space
  • u16 data: Data to be written

Description

Writes 16 bits of data to the specified offset within the local device's configuration space.

rio_local_read_config_8() #

int rio_local_read_config_8(struct rio_mport *port, u32 offset, u8 * data)

Read 8 bits from local configuration space

Parameters

  • struct rio_mport *port: Master port
  • u32 offset: Offset into local configuration space
  • u8 * data: Pointer to read data into

Description

Reads 8 bits of data from the specified offset within the local device's configuration space.

rio_local_write_config_8() #

int rio_local_write_config_8(struct rio_mport *port, u32 offset, u8 data)

Write 8 bits to local configuration space

Parameters

  • struct rio_mport *port: Master port
  • u32 offset: Offset into local configuration space
  • u8 data: Data to be written

Description

Writes 8 bits of data to the specified offset within the local device's configuration space.

rio_read_config_32() #

int rio_read_config_32(struct rio_dev *rdev, u32 offset, u32 * data)

Read 32 bits from configuration space

Parameters

  • struct rio_dev *rdev: RIO device
  • u32 offset: Offset into device configuration space
  • u32 * data: Pointer to read data into

Description

Reads 32 bits of data from the specified offset within the RIO device's configuration space.

rio_write_config_32() #

int rio_write_config_32(struct rio_dev *rdev, u32 offset, u32 data)

Write 32 bits to configuration space

Parameters

  • struct rio_dev *rdev: RIO device
  • u32 offset: Offset into device configuration space
  • u32 data: Data to be written

Description

Writes 32 bits of data to the specified offset within the RIO device's configuration space.

rio_read_config_16() #

int rio_read_config_16(struct rio_dev *rdev, u32 offset, u16 * data)

Read 16 bits from configuration space

Parameters

  • struct rio_dev *rdev: RIO device
  • u32 offset: Offset into device configuration space
  • u16 * data: Pointer to read data into

Description

Reads 16 bits of data from the specified offset within the RIO device's configuration space.

rio_write_config_16() #

int rio_write_config_16(struct rio_dev *rdev, u32 offset, u16 data)

Write 16 bits to configuration space

Parameters

  • struct rio_dev *rdev: RIO device
  • u32 offset: Offset into device configuration space
  • u16 data: Data to be written

Description

Writes 16 bits of data to the specified offset within the RIO device's configuration space.

rio_read_config_8() #

int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data)

Read 8 bits from configuration space

Parameters

  • struct rio_dev *rdev: RIO device
  • u32 offset: Offset into device configuration space
  • u8 * data: Pointer to read data into

Description

Reads 8 bits of data from the specified offset within the RIO device's configuration space.

rio_write_config_8() #

int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data)

Write 8 bits to configuration space

Parameters

  • struct rio_dev *rdev: RIO device
  • u32 offset: Offset into device configuration space
  • u8 data: Data to be written

Description

Writes 8 bits of data to the specified offset within the RIO device's configuration space.

rio_send_doorbell() #

int rio_send_doorbell(struct rio_dev *rdev, u16 data)

Send a doorbell message to a device

Parameters

  • struct rio_dev *rdev: RIO device
  • u16 data: Doorbell message data

Description

Send a doorbell message to a RIO device. The doorbell message has a 16-bit info field provided by the data argument.

rio_init_mbox_res() #

void rio_init_mbox_res(struct resource *res, int start, int end)

Initialize a RIO mailbox resource

Parameters

  • struct resource *res: resource struct
  • int start: start of mailbox range
  • int end: end of mailbox range

Description

This function is used to initialize the fields of a resource for use as a mailbox resource. It initializes a range of mailboxes using the start and end arguments.

rio_init_dbell_res() #

void rio_init_dbell_res(struct resource *res, u16 start, u16 end)

Initialize a RIO doorbell resource

Parameters

  • struct resource *res: resource struct
  • u16 start: start of doorbell range
  • u16 end: end of doorbell range

Description

This function is used to initialize the fields of a resource for use as a doorbell resource. It initializes a range of doorbell messages using the start and end arguments.

RIO_DEVICE() #

RIO_DEVICE(dev, ven)

macro used to describe a specific RIO device

Parameters

  • dev: the 16 bit RIO device ID
  • ven: the 16 bit RIO vendor ID

Description

This macro is used to create a struct rio_device_id that matches a specific device. The assembly vendor and assembly device fields will be set to RIO_ANY_ID.

rio_add_outb_message() #

int rio_add_outb_message(struct rio_mport *mport, struct rio_dev *rdev, int mbox, void *buffer, size_t len)

Add RIO message to an outbound mailbox queue

Parameters

  • struct rio_mport *mport: RIO master port containing the outbound queue
  • struct rio_dev *rdev: RIO device the message is be sent to
  • int mbox: The outbound mailbox queue
  • void *buffer: Pointer to the message buffer
  • size_t len: Length of the message buffer

Description

Adds a RIO message buffer to an outbound mailbox queue for transmission. Returns 0 on success.

rio_add_inb_buffer() #

int rio_add_inb_buffer(struct rio_mport *mport, int mbox, void *buffer)

Add buffer to an inbound mailbox queue

Parameters

  • struct rio_mport *mport: Master port containing the inbound mailbox
  • int mbox: The inbound mailbox number
  • void *buffer: Pointer to the message buffer

Description

Adds a buffer to an inbound mailbox queue for reception. Returns 0 on success.

rio_get_inb_message() #

void * rio_get_inb_message(struct rio_mport *mport, int mbox)

Get A RIO message from an inbound mailbox queue

Parameters

  • struct rio_mport *mport: Master port containing the inbound mailbox
  • int mbox: The inbound mailbox number

Description

Get a RIO message from an inbound mailbox queue. Returns 0 on success.

rio_name() #

const char * rio_name(struct rio_dev *rdev)

Get the unique RIO device identifier

Parameters

  • struct rio_dev *rdev: RIO device

Description

Get the unique RIO device identifier. Returns the device identifier string.

rio_get_drvdata() #

void * rio_get_drvdata(struct rio_dev *rdev)

Get RIO driver specific data

Parameters

  • struct rio_dev *rdev: RIO device

Description

Get RIO driver specific data. Returns a pointer to the driver specific data.

rio_set_drvdata() #

void rio_set_drvdata(struct rio_dev *rdev, void *data)

Set RIO driver specific data

Parameters

  • struct rio_dev *rdev: RIO device
  • void *data: Pointer to driver specific data

Description

Set RIO driver specific data. device struct driver data pointer is set to the data argument.

rio_dev_get() #

struct rio_dev * rio_dev_get(struct rio_dev *rdev)

Increments the reference count of the RIO device structure

Parameters

  • struct rio_dev *rdev: RIO device being referenced

Description

Each live reference to a device should be refcounted.

Drivers for RIO devices should normally record such references in their probe() methods, when they bind to a device, and release them by calling rio_dev_put(), in their disconnect() methods.

rio_dev_put() #

void rio_dev_put(struct rio_dev *rdev)

Release a use of the RIO device structure

Parameters

  • struct rio_dev *rdev: RIO device being disconnected

Description

Must be called when a user of a device is finished with it. When the last user of the device calls this function, the memory of the device is freed.

rio_register_driver() #

int rio_register_driver(struct rio_driver *rdrv)

register a new RIO driver

Parameters

  • struct rio_driver *rdrv: the RIO driver structure to register

Description

Adds a struct rio_driver to the list of registered drivers. Returns a negative value on error, otherwise 0. If no error occurred, the driver remains registered even if no device was claimed during registration.

rio_unregister_driver() #

void rio_unregister_driver(struct rio_driver *rdrv)

unregister a RIO driver

Parameters

  • struct rio_driver *rdrv: the RIO driver structure to unregister

Description

Deletes the struct rio_driver from the list of registered RIO drivers, gives it a chance to clean up by calling its remove() function for each device it was responsible for, and marks those devices as driverless.

rio_local_get_device_id() #

u16 rio_local_get_device_id(struct rio_mport *port)

Get the base/extended device id for a port

Parameters

  • struct rio_mport *port: RIO master port from which to get the deviceid

Description

Reads the base/extended device id from the local device implementing the master port. Returns the 8/16-bit device id.

rio_query_mport() #

int rio_query_mport(struct rio_mport *port, struct rio_mport_attr *mport_attr)

Query mport device attributes

Parameters

  • struct rio_mport *port: mport device to query
  • struct rio_mport_attr *mport_attr: mport attributes data structure

Description

Returns attributes of specified mport through the pointer to attributes data structure.

rio_alloc_net() #

struct rio_net * rio_alloc_net(struct rio_mport *mport)

Allocate and initialize a new RIO network data structure

Parameters

  • struct rio_mport *mport: Master port associated with the RIO network

Description

Allocates a RIO network structure, initializes per-network list heads, and adds the associated master port to the network list of associated master ports. Returns a RIO network pointer on success or NULL on failure.

rio_local_set_device_id() #

void rio_local_set_device_id(struct rio_mport *port, u16 did)

Set the base/extended device id for a port

Parameters

  • struct rio_mport *port: RIO master port
  • u16 did: Device ID value to be written

Description

Writes the base/extended device id from a device.

rio_add_device() #

int rio_add_device(struct rio_dev *rdev)

Adds a RIO device to the device model

Parameters

  • struct rio_dev *rdev: RIO device

Description

Adds the RIO device to the global device list and adds the RIO device to the RIO device list. Creates the generic sysfs nodes for an RIO device.

rio_request_inb_mbox() #

int rio_request_inb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries, void (*minb) (struct rio_mport * mport, void *dev_id, int mbox, int slot))

request inbound mailbox service

Parameters

  • struct rio_mport *mport: RIO master port from which to allocate the mailbox resource
  • void *dev_id: Device specific pointer to pass on event
  • int mbox: Mailbox number to claim
  • int entries: Number of entries in inbound mailbox queue
  • void (*minb) (struct rio_mport * mport, void *dev_id, int mbox, int slot): Callback to execute when inbound message is received

Description

Requests ownership of an inbound mailbox resource and binds a callback function to the resource. Returns 0 on success.

rio_release_inb_mbox() #

int rio_release_inb_mbox(struct rio_mport *mport, int mbox)

release inbound mailbox message service

Parameters

  • struct rio_mport *mport: RIO master port from which to release the mailbox resource
  • int mbox: Mailbox number to release

Description

Releases ownership of an inbound mailbox resource. Returns 0 if the request has been satisfied.

rio_request_outb_mbox() #

int rio_request_outb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries, void (*moutb) (struct rio_mport * mport, void *dev_id, int mbox, int slot))

request outbound mailbox service

Parameters

  • struct rio_mport *mport: RIO master port from which to allocate the mailbox resource
  • void *dev_id: Device specific pointer to pass on event
  • int mbox: Mailbox number to claim
  • int entries: Number of entries in outbound mailbox queue
  • void (*moutb) (struct rio_mport * mport, void *dev_id, int mbox, int slot): Callback to execute when outbound message is sent

Description

Requests ownership of an outbound mailbox resource and binds a callback function to the resource. Returns 0 on success.

rio_release_outb_mbox() #

int rio_release_outb_mbox(struct rio_mport *mport, int mbox)

release outbound mailbox message service

Parameters

  • struct rio_mport *mport: RIO master port from which to release the mailbox resource
  • int mbox: Mailbox number to release

Description

Releases ownership of an inbound mailbox resource. Returns 0 if the request has been satisfied.

rio_request_inb_dbell() #

int rio_request_inb_dbell(struct rio_mport *mport, void *dev_id, u16 start, u16 end, void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src, u16 dst, u16 info))

request inbound doorbell message service

Parameters

  • struct rio_mport *mport: RIO master port from which to allocate the doorbell resource
  • void *dev_id: Device specific pointer to pass on event
  • u16 start: Doorbell info range start
  • u16 end: Doorbell info range end
  • void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src, u16 dst, u16 info): Callback to execute when doorbell is received

Description

Requests ownership of an inbound doorbell resource and binds a callback function to the resource. Returns 0 if the request has been satisfied.

rio_release_inb_dbell() #

int rio_release_inb_dbell(struct rio_mport *mport, u16 start, u16 end)

release inbound doorbell message service

Parameters

  • struct rio_mport *mport: RIO master port from which to release the doorbell resource
  • u16 start: Doorbell info range start
  • u16 end: Doorbell info range end

Description

Releases ownership of an inbound doorbell resource and removes callback from the doorbell event list. Returns 0 if the request has been satisfied.

rio_request_outb_dbell() #

struct resource * rio_request_outb_dbell(struct rio_dev *rdev, u16 start, u16 end)

request outbound doorbell message range

Parameters

  • struct rio_dev *rdev: RIO device from which to allocate the doorbell resource
  • u16 start: Doorbell message range start
  • u16 end: Doorbell message range end

Description

Requests ownership of a doorbell message range. Returns a resource if the request has been satisfied or NULL on failure.

rio_release_outb_dbell() #

int rio_release_outb_dbell(struct rio_dev *rdev, struct resource *res)

release outbound doorbell message range

Parameters

  • struct rio_dev *rdev: RIO device from which to release the doorbell resource
  • struct resource *res: Doorbell resource to be freed

Description

Releases ownership of a doorbell message range. Returns 0 if the request has been satisfied.

rio_add_mport_pw_handler() #

int rio_add_mport_pw_handler(struct rio_mport *mport, void *context, int (*pwcback)(struct rio_mport *mport, void *context, union rio_pw_msg *msg, int step))

add port-write message handler into the list of mport specific pw handlers

Parameters

  • struct rio_mport *mport: RIO master port to bind the portwrite callback
  • void *context: Handler specific context to pass on event
  • int (*pwcback)(struct rio_mport *mport, void *context, union rio_pw_msg *msg, int step): Callback to execute when portwrite is received

Description

Returns 0 if the request has been satisfied.

rio_del_mport_pw_handler() #

int rio_del_mport_pw_handler(struct rio_mport *mport, void *context, int (*pwcback)(struct rio_mport *mport, void *context, union rio_pw_msg *msg, int step))

remove port-write message handler from the list of mport specific pw handlers

Parameters

  • struct rio_mport *mport: RIO master port to bind the portwrite callback
  • void *context: Registered handler specific context to pass on event
  • int (*pwcback)(struct rio_mport *mport, void *context, union rio_pw_msg *msg, int step): Registered callback function

Description

Returns 0 if the request has been satisfied.

rio_request_inb_pwrite() #

int rio_request_inb_pwrite(struct rio_dev *rdev, int (*pwcback)(struct rio_dev *rdev, union rio_pw_msg *msg, int step))

request inbound port-write message service for specific RapidIO device

Parameters

  • struct rio_dev *rdev: RIO device to which register inbound port-write callback routine
  • int (*pwcback)(struct rio_dev *rdev, union rio_pw_msg *msg, int step): Callback routine to execute when port-write is received

Description

Binds a port-write callback function to the RapidIO device. Returns 0 if the request has been satisfied.

rio_release_inb_pwrite() #

int rio_release_inb_pwrite(struct rio_dev *rdev)

release inbound port-write message service associated with specific RapidIO device

Parameters

  • struct rio_dev *rdev: RIO device which registered for inbound port-write callback

Description

Removes callback from the rio_dev structure. Returns 0 if the request has been satisfied.

rio_pw_enable() #

void rio_pw_enable(struct rio_mport *mport, int enable)

Enables/disables port-write handling by a master port

Parameters

  • struct rio_mport *mport: Master port associated with port-write handling
  • int enable: 1=enable, 0=disable

rio_map_inb_region() #

int rio_map_inb_region(struct rio_mport *mport, dma_addr_t local, u64 rbase, u32 size, u32 rflags)
  • Map inbound memory region.

Parameters

  • struct rio_mport *mport: Master port.
  • dma_addr_t local: physical address of memory region to be mapped
  • u64 rbase: RIO base address assigned to this window
  • u32 size: Size of the memory region
  • u32 rflags: Flags for mapping.

Return

0 -- Success.

Description

This function will create the mapping from RIO space to local memory.

rio_unmap_inb_region() #

void rio_unmap_inb_region(struct rio_mport *mport, dma_addr_t lstart)
  • Unmap the inbound memory region

Parameters

  • struct rio_mport *mport: Master port
  • dma_addr_t lstart: physical address of memory region to be unmapped

rio_map_outb_region() #

int rio_map_outb_region(struct rio_mport *mport, u16 destid, u64 rbase, u32 size, u32 rflags, dma_addr_t *local)
  • Map outbound memory region.

Parameters

  • struct rio_mport *mport: Master port.
  • u16 destid: destination id window points to
  • u64 rbase: RIO base address window translates to
  • u32 size: Size of the memory region
  • u32 rflags: Flags for mapping.
  • dma_addr_t *local: physical address of memory region mapped

Return

0 -- Success.

Description

This function will create the mapping from RIO space to local memory.

rio_unmap_outb_region() #

void rio_unmap_outb_region(struct rio_mport *mport, u16 destid, u64 rstart)
  • Unmap the inbound memory region

Parameters

  • struct rio_mport *mport: Master port
  • u16 destid: destination id mapping points to
  • u64 rstart: RIO base address window translates to

rio_mport_get_physefb() #

u32 rio_mport_get_physefb(struct rio_mport *port, int local, u16 destid, u8 hopcount, u32 *rmap)

Helper function that returns register offset for Physical Layer Extended Features Block.

Parameters

  • struct rio_mport *port: Master port to issue transaction
  • int local: Indicate a local master port or remote device access
  • u16 destid: Destination ID of the device
  • u8 hopcount: Number of switch hops to the device
  • u32 *rmap: pointer to location to store register map type info

rio_get_comptag() #

struct rio_dev * rio_get_comptag(u32 comp_tag, struct rio_dev *from)

Begin or continue searching for a RIO device by component tag

Parameters

  • u32 comp_tag: RIO component tag to match
  • struct rio_dev *from: Previous RIO device found in search, or NULL for new search

Description

Iterates through the list of known RIO devices. If a RIO device is found with a matching comp_tag, a pointer to its device structure is returned. Otherwise, NULL is returned. A new search is initiated by passing NULL to the from argument. Otherwise, if from is not NULL, searches continue from next device on the global list.

rio_set_port_lockout() #

int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)

Sets/clears LOCKOUT bit (RIO EM 1.3) for a switch port.

Parameters

  • struct rio_dev *rdev: Pointer to RIO device control structure
  • u32 pnum: Switch port number to set LOCKOUT bit
  • int lock: Operation : set (=1) or clear (=0)

rio_enable_rx_tx_port() #

int rio_enable_rx_tx_port(struct rio_mport *port, int local, u16 destid, u8 hopcount, u8 port_num)

enable input receiver and output transmitter of given port

Parameters

  • struct rio_mport *port: Master port associated with the RIO network
  • int local: local=1 select local port otherwise a far device is reached
  • u16 destid: Destination ID of the device to check host bit
  • u8 hopcount: Number of hops to reach the target
  • u8 port_num: Port (-number on switch) to enable on a far end device

Description

Returns 0 or 1 from on General Control Command and Status Register (EXT_PTR+0x3C)

rio_mport_chk_dev_access() #

int rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid, u8 hopcount)

Validate access to the specified device.

Parameters

  • struct rio_mport *mport: Master port to send transactions
  • u16 destid: Device destination ID in network
  • u8 hopcount: Number of hops into the network

rio_inb_pwrite_handler() #

int rio_inb_pwrite_handler(struct rio_mport *mport, union rio_pw_msg *pw_msg)

inbound port-write message handler

Parameters

  • struct rio_mport *mport: mport device associated with port-write
  • union rio_pw_msg *pw_msg: pointer to inbound port-write message

Description

Processes an inbound port-write message. Returns 0 if the request has been satisfied.

rio_mport_get_efb() #

u32 rio_mport_get_efb(struct rio_mport *port, int local, u16 destid, u8 hopcount, u32 from)

get pointer to next extended features block

Parameters

  • struct rio_mport *port: Master port to issue transaction
  • int local: Indicate a local master port or remote device access
  • u16 destid: Destination ID of the device
  • u8 hopcount: Number of switch hops to the device
  • u32 from: Offset of current Extended Feature block header (if 0 starts from ExtFeaturePtr)

rio_mport_get_feature() #

u32 rio_mport_get_feature(struct rio_mport * port, int local, u16 destid, u8 hopcount, int ftr)

query for devices' extended features

Parameters

  • struct rio_mport * port: Master port to issue transaction
  • int local: Indicate a local master port or remote device access
  • u16 destid: Destination ID of the device
  • u8 hopcount: Number of switch hops to the device
  • int ftr: Extended feature code

Description

Tell if a device supports a given RapidIO capability. Returns the offset of the requested extended feature block within the device's RIO configuration space or 0 in case the device does not support it.

rio_lock_device() #

int rio_lock_device(struct rio_mport *port, u16 destid, u8 hopcount, int wait_ms)

Acquires host device lock for specified device

Parameters

  • struct rio_mport *port: Master port to send transaction
  • u16 destid: Destination ID for device/switch
  • u8 hopcount: Hopcount to reach switch
  • int wait_ms: Max wait time in msec (0 = no timeout)

Description

Attepts to acquire host device lock for specified device Returns 0 if device lock acquired or EINVAL if timeout expires.

rio_unlock_device() #

int rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount)

Releases host device lock for specified device

Parameters

  • struct rio_mport *port: Master port to send transaction
  • u16 destid: Destination ID for device/switch
  • u8 hopcount: Hopcount to reach switch

Description

Returns 0 if device lock released or EINVAL if fails.

rio_route_add_entry() #

int rio_route_add_entry(struct rio_dev *rdev, u16 table, u16 route_destid, u8 route_port, int lock)

Add a route entry to a switch routing table

Parameters

  • struct rio_dev *rdev: RIO device
  • u16 table: Routing table ID
  • u16 route_destid: Destination ID to be routed
  • u8 route_port: Port number to be routed
  • int lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)

Description

If available calls the switch specific add_entry() method to add a route entry into a switch routing table. Otherwise uses standard RT update method as defined by RapidIO specification. A specific routing table can be selected using the table argument if a switch has per port routing tables or the standard (or global) table may be used by passing RIO_GLOBAL_TABLE in table.

Returns 0 on success or -EINVAL on failure.

rio_route_get_entry() #

int rio_route_get_entry(struct rio_dev *rdev, u16 table, u16 route_destid, u8 *route_port, int lock)

Read an entry from a switch routing table

Parameters

  • struct rio_dev *rdev: RIO device
  • u16 table: Routing table ID
  • u16 route_destid: Destination ID to be routed
  • u8 *route_port: Pointer to read port number into
  • int lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)

Description

If available calls the switch specific get_entry() method to fetch a route entry from a switch routing table. Otherwise uses standard RT read method as defined by RapidIO specification. A specific routing table can be selected using the table argument if a switch has per port routing tables or the standard (or global) table may be used by passing RIO_GLOBAL_TABLE in table.

Returns 0 on success or -EINVAL on failure.

rio_route_clr_table() #

int rio_route_clr_table(struct rio_dev *rdev, u16 table, int lock)

Clear a switch routing table

Parameters

  • struct rio_dev *rdev: RIO device
  • u16 table: Routing table ID
  • int lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)

Description

If available calls the switch specific clr_table() method to clear a switch routing table. Otherwise uses standard RT write method as defined by RapidIO specification. A specific routing table can be selected using the table argument if a switch has per port routing tables or the standard (or global) table may be used by passing RIO_GLOBAL_TABLE in table.

Returns 0 on success or -EINVAL on failure.

rio_request_mport_dma() #

struct dma_chan * rio_request_mport_dma(struct rio_mport *mport)

request RapidIO capable DMA channel associated with specified local RapidIO mport device.

Parameters

  • struct rio_mport *mport: RIO mport to perform DMA data transfers

Description

Returns pointer to allocated DMA channel or NULL if failed.

rio_release_dma() #

void rio_release_dma(struct dma_chan *dchan)

release specified DMA channel

Parameters

  • struct dma_chan *dchan: DMA channel to release

rio_dma_prep_xfer() #

struct dma_async_tx_descriptor * rio_dma_prep_xfer(struct dma_chan *dchan, u16 destid, struct rio_dma_data *data, enum dma_transfer_direction direction, unsigned long flags)

RapidIO specific wrapper for device_prep_slave_sg callback defined by DMAENGINE.

Parameters

  • struct dma_chan *dchan: DMA channel to configure
  • u16 destid: target RapidIO device destination ID
  • struct rio_dma_data *data: RIO specific data descriptor
  • enum dma_transfer_direction direction: DMA data transfer direction (TO or FROM the device)
  • unsigned long flags: dmaengine defined flags

Description

Initializes RapidIO capable DMA channel for the specified data transfer. Uses DMA channel private extension to pass information related to remote target RIO device.

Return

pointer to DMA transaction descriptor if successful, error-valued pointer or NULL if failed.

rio_register_scan() #

int rio_register_scan(int mport_id, struct rio_scan *scan_ops)

enumeration/discovery method registration interface

Parameters

  • int mport_id: mport device ID for which fabric scan routine has to be set (RIO_MPORT_ANY = set for all available mports)
  • struct rio_scan *scan_ops: enumeration/discovery operations structure

Description

Registers enumeration/discovery operations with RapidIO subsystem and attaches it to the specified mport device (or all available mports if RIO_MPORT_ANY is specified).

Returns error if the mport already has an enumerator attached to it. In case of RIO_MPORT_ANY skips mports with valid scan routines (no error).

Internals #

This chapter contains the autogenerated documentation of the RapidIO subsystem.

Structures #

struct rio_switch #

RIO switch info

Definition

struct rio_switch {
    struct list_head node;
    u8 *route_table;
    u32 port_ok;
    struct rio_switch_ops *ops;
    spinlock_t lock;
    struct rio_dev *nextdev[];
};

Members

  • node: Node in global list of switches
  • route_table: Copy of switch routing table
  • port_ok: Status of each port (one bit per port) - OK=1 or UNINIT=0
  • ops: pointer to switch-specific operations
  • lock: lock to serialize operations updates
  • nextdev: Array of per-port pointers to the next attached device

struct rio_switch_ops #

Per-switch operations

Definition

struct rio_switch_ops {
    struct module *owner;
    int (*add_entry) (struct rio_mport *mport, u16 destid, u8 hopcount, u16 table, u16 route_destid, u8 route_port);
    int (*get_entry) (struct rio_mport *mport, u16 destid, u8 hopcount, u16 table, u16 route_destid, u8 *route_port);
    int (*clr_table) (struct rio_mport *mport, u16 destid, u8 hopcount, u16 table);
    int (*set_domain) (struct rio_mport *mport, u16 destid, u8 hopcount, u8 sw_domain);
    int (*get_domain) (struct rio_mport *mport, u16 destid, u8 hopcount, u8 *sw_domain);
    int (*em_init) (struct rio_dev *dev);
    int (*em_handle) (struct rio_dev *dev, u8 swport);
};

Members

  • owner: The module owner of this structure
  • add_entry: Callback for switch-specific route add function
  • get_entry: Callback for switch-specific route get function
  • clr_table: Callback for switch-specific clear route table function
  • set_domain: Callback for switch-specific domain setting function
  • get_domain: Callback for switch-specific domain get function
  • em_init: Callback for switch-specific error management init function
  • em_handle: Callback for switch-specific error management handler function

Description

Defines the operations that are necessary to initialize/control a particular RIO switch device.

struct rio_dev #

RIO device info

Definition

struct rio_dev {
    struct list_head global_list;
    struct list_head net_list;
    struct rio_net *net;
    bool do_enum;
    u16 did;
    u16 vid;
    u32 device_rev;
    u16 asm_did;
    u16 asm_vid;
    u16 asm_rev;
    u16 efptr;
    u32 pef;
    u32 swpinfo;
    u32 src_ops;
    u32 dst_ops;
    u32 comp_tag;
    u32 phys_efptr;
    u32 phys_rmap;
    u32 em_efptr;
    u64 dma_mask;
    struct rio_driver *driver;
    struct device dev;
    struct resource riores[RIO_MAX_DEV_RESOURCES];
    int (*pwcback) (struct rio_dev *rdev, union rio_pw_msg *msg, int step);
    u16 destid;
    u8 hopcount;
    struct rio_dev *prev;
    atomic_t state;
    struct rio_switch rswitch[];
};

Members

  • global_list: Node in list of all RIO devices
  • net_list: Node in list of RIO devices in a network
  • net: Network this device is a part of
  • do_enum: Enumeration flag
  • did: Device ID
  • vid: Vendor ID
  • device_rev: Device revision
  • asm_did: Assembly device ID
  • asm_vid: Assembly vendor ID
  • asm_rev: Assembly revision
  • efptr: Extended feature pointer
  • pef: Processing element features
  • swpinfo: Switch port info
  • src_ops: Source operation capabilities
  • dst_ops: Destination operation capabilities
  • comp_tag: RIO component tag
  • phys_efptr: RIO device extended features pointer
  • phys_rmap: LP-Serial Register Map Type (1 or 2)
  • em_efptr: RIO Error Management features pointer
  • dma_mask: Mask of bits of RIO address this device implements
  • driver: Driver claiming this device
  • dev: Device model device
  • riores: RIO resources this device owns
  • pwcback: port-write callback function for this device
  • destid: Network destination ID (or associated destid for switch)
  • hopcount: Hopcount to this device
  • prev: Previous RIO device connected to the current one
  • state: device state
  • rswitch: struct rio_switch (if valid for this device)

struct rio_msg #

RIO message event

Definition

struct rio_msg {
    struct resource *res;
    void (*mcback) (struct rio_mport * mport, void *dev_id, int mbox, int slot);
};

Members

  • res: Mailbox resource
  • mcback: Message event callback

struct rio_dbell #

RIO doorbell event

Definition

struct rio_dbell {
    struct list_head node;
    struct resource *res;
    void (*dinb) (struct rio_mport *mport, void *dev_id, u16 src, u16 dst, u16 info);
    void *dev_id;
};

Members

  • node: Node in list of doorbell events
  • res: Doorbell resource
  • dinb: Doorbell event callback
  • dev_id: Device specific pointer to pass on event

struct rio_mport #

RIO master port info

Definition

struct rio_mport {
        struct list_head dbells;
        struct list_head pwrites;
        struct list_head node;
        struct list_head nnode;
        struct rio_net *net;
        struct mutex lock;
        struct resource iores;
        struct resource riores[RIO_MAX_MPORT_RESOURCES];
        struct rio_msg inb_msg[RIO_MAX_MBOX];
        struct rio_msg outb_msg[RIO_MAX_MBOX];
        int host_deviceid;
        struct rio_ops *ops;
        unsigned char id;
        unsigned char index;
        unsigned int sys_size;
        u32 phys_efptr;
        u32 phys_rmap;
        unsigned char name[RIO_MAX_MPORT_NAME];
        struct device dev;
        void *priv;
    #ifdef CONFIG_RAPIDIO_DMA_ENGINE;
        struct dma_device       dma;
    #endif;
        struct rio_scan *nscan;
        atomic_t state;
        unsigned int pwe_refcnt;
};

Members

  • dbells: List of doorbell events
  • pwrites: List of portwrite events
  • node: Node in global list of master ports
  • nnode: Node in network list of master ports
  • net: RIO net this mport is attached to
  • lock: lock to synchronize lists manipulations
  • iores: I/O mem resource that this master port interface owns
  • riores: RIO resources that this master port interfaces owns
  • inb_msg: RIO inbound message event descriptors
  • outb_msg: RIO outbound message event descriptors
  • host_deviceid: Host device ID associated with this master port
  • ops: configuration space functions
  • id: Port ID, unique among all ports
  • index: Port index, unique among all port interfaces of the same type
  • sys_size: RapidIO common transport system size
  • phys_efptr: RIO port extended features pointer
  • phys_rmap: LP-Serial EFB Register Mapping type (1 or 2).
  • name: Port name string
  • dev: device structure associated with an mport
  • priv: Master port private data
  • dma: DMA device associated with mport
  • nscan: RapidIO network enumeration/discovery operations
  • state: mport device state
  • pwe_refcnt: port-write enable ref counter to track enable/disable requests

struct rio_net #

RIO network info

Definition

struct rio_net {
    struct list_head node;
    struct list_head devices;
    struct list_head switches;
    struct list_head mports;
    struct rio_mport *hport;
    unsigned char id;
    struct device dev;
    void *enum_data;
    void (*release)(struct rio_net *net);
};

Members

  • node: Node in global list of RIO networks
  • devices: List of devices in this network
  • switches: List of switches in this network
  • mports: List of master ports accessing this network
  • hport: Default port for accessing this network
  • id: RIO network ID
  • dev: Device object
  • enum_data: private data specific to a network enumerator
  • release: enumerator-specific release callback

struct rio_mport_attr #

RIO mport device attributes

Definition

struct rio_mport_attr {
    int flags;
    int link_speed;
    int link_width;
    int dma_max_sge;
    int dma_max_size;
    int dma_align;
};

Members

  • flags: mport device capability flags
  • link_speed: SRIO link speed value (as defined by RapidIO specification)
  • link_width: SRIO link width value (as defined by RapidIO specification)
  • dma_max_sge: number of SG list entries that can be handled by DMA channel(s)
  • dma_max_size: max number of bytes in single DMA transfer (SG entry)
  • dma_align: alignment shift for DMA operations (as for other DMA operations)

struct rio_ops #

Low-level RIO configuration space operations

Definition

struct rio_ops {
    int (*lcread) (struct rio_mport *mport, int index, u32 offset, int len, u32 *data);
    int (*lcwrite) (struct rio_mport *mport, int index, u32 offset, int len, u32 data);
    int (*cread) (struct rio_mport *mport, int index, u16 destid, u8 hopcount, u32 offset, int len, u32 *data);
    int (*cwrite) (struct rio_mport *mport, int index, u16 destid, u8 hopcount, u32 offset, int len, u32 data);
    int (*dsend) (struct rio_mport *mport, int index, u16 destid, u16 data);
    int (*pwenable) (struct rio_mport *mport, int enable);
    int (*open_outb_mbox)(struct rio_mport *mport, void *dev_id, int mbox, int entries);
    void (*close_outb_mbox)(struct rio_mport *mport, int mbox);
    int (*open_inb_mbox)(struct rio_mport *mport, void *dev_id, int mbox, int entries);
    void (*close_inb_mbox)(struct rio_mport *mport, int mbox);
    int (*add_outb_message)(struct rio_mport *mport, struct rio_dev *rdev, int mbox, void *buffer, size_t len);
    int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
    void *(*get_inb_message)(struct rio_mport *mport, int mbox);
    int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart, u64 rstart, u64 size, u32 flags);
    void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
    int (*query_mport)(struct rio_mport *mport, struct rio_mport_attr *attr);
    int (*map_outb)(struct rio_mport *mport, u16 destid, u64 rstart, u32 size, u32 flags, dma_addr_t *laddr);
    void (*unmap_outb)(struct rio_mport *mport, u16 destid, u64 rstart);
};

Members

  • lcread: Callback to perform local (master port) read of config space.
  • lcwrite: Callback to perform local (master port) write of config space.
  • cread: Callback to perform network read of config space.
  • cwrite: Callback to perform network write of config space.
  • dsend: Callback to send a doorbell message.
  • pwenable: Callback to enable/disable port-write message handling.
  • open_outb_mbox: Callback to initialize outbound mailbox.
  • close_outb_mbox: Callback to shut down outbound mailbox.
  • open_inb_mbox: Callback to initialize inbound mailbox.
  • close_inb_mbox: Callback to shut down inbound mailbox.
  • add_outb_message: Callback to add a message to an outbound mailbox queue.
  • add_inb_buffer: Callback to add a buffer to an inbound mailbox queue.
  • get_inb_message: Callback to get a message from an inbound mailbox queue.
  • map_inb: Callback to map RapidIO address region into local memory space.
  • unmap_inb: Callback to unmap RapidIO address region mapped with map_inb().
  • query_mport: Callback to query mport device attributes.
  • map_outb: Callback to map outbound address region into local memory space.
  • unmap_outb: Callback to unmap outbound RapidIO address region.

struct rio_driver #

RIO driver info

Definition

struct rio_driver {
    struct list_head node;
    char *name;
    const struct rio_device_id *id_table;
    int (*probe) (struct rio_dev * dev, const struct rio_device_id * id);
    void (*remove) (struct rio_dev * dev);
    void (*shutdown)(struct rio_dev *dev);
    int (*suspend) (struct rio_dev * dev, u32 state);
    int (*resume) (struct rio_dev * dev);
    int (*enable_wake) (struct rio_dev * dev, u32 state, int enable);
    struct device_driver driver;
};

Members

  • node: Node in list of drivers
  • name: RIO driver name
  • id_table: RIO device ids to be associated with this driver
  • probe: RIO device inserted
  • remove: RIO device removed
  • shutdown: shutdown notification callback
  • suspend: RIO device suspended
  • resume: RIO device awakened
  • enable_wake: RIO device enable wake event
  • driver: LDM driver struct

Description

Provides info on a RIO device driver for insertion/removal and power management purposes.

struct rio_scan #

RIO enumeration and discovery operations

Definition

struct rio_scan {
    struct module *owner;
    int (*enumerate)(struct rio_mport *mport, u32 flags);
    int (*discover)(struct rio_mport *mport, u32 flags);
};

Members

  • owner: The module owner of this structure
  • enumerate: Callback to perform RapidIO fabric enumeration.
  • discover: Callback to perform RapidIO fabric discovery.

struct rio_scan_node #

list node to register RapidIO enumeration and discovery methods with RapidIO core.

Definition

struct rio_scan_node {
    int mport_id;
    struct list_head node;
    struct rio_scan *ops;
};

Members

  • mport_id: ID of an mport (net) serviced by this enumerator
  • node: node in global list of registered enumerators
  • ops: RIO enumeration and discovery operations

Enumeration and Discovery #

rio_destid_alloc() #

u16 rio_destid_alloc(struct rio_net *net)

Allocate next available destID for given network

Parameters

  • struct rio_net *net: RIO network

Description

Returns next available device destination ID for the specified RIO network. Marks allocated ID as one in use. Returns RIO_INVALID_DESTID if new destID is not available.

rio_destid_reserve() #

int rio_destid_reserve(struct rio_net *net, u16 destid)

Reserve the specified destID

Parameters

  • struct rio_net *net: RIO network
  • u16 destid: destID to reserve

Description

Tries to reserve the specified destID. Returns 0 if successful.

rio_destid_free() #

void rio_destid_free(struct rio_net *net, u16 destid)

free a previously allocated destID

Parameters

  • struct rio_net *net: RIO network
  • u16 destid: destID to free

Description

Makes the specified destID available for use.

rio_destid_first() #

u16 rio_destid_first(struct rio_net *net)

return first destID in use

Parameters

  • struct rio_net *net: RIO network

rio_destid_next() #

u16 rio_destid_next(struct rio_net *net, u16 from)

return next destID in use

Parameters

  • struct rio_net *net: RIO network
  • u16 from: destination ID from which search shall continue

rio_get_device_id() #

u16 rio_get_device_id(struct rio_mport *port, u16 destid, u8 hopcount)

Get the base/extended device id for a device

Parameters

  • struct rio_mport *port: RIO master port
  • u16 destid: Destination ID of device
  • u8 hopcount: Hopcount to device

Description

Reads the base/extended device id from a device. Returns the 8/16-bit device ID.

rio_set_device_id() #

void rio_set_device_id(struct rio_mport *port, u16 destid, u8 hopcount, u16 did)

Set the base/extended device id for a device

Parameters

  • struct rio_mport *port: RIO master port
  • u16 destid: Destination ID of device
  • u8 hopcount: Hopcount to device
  • u16 did: Device ID value to be written

Description

Writes the base/extended device id from a device.

rio_clear_locks() #

int rio_clear_locks(struct rio_net *net)

Release all host locks and signal enumeration complete

Parameters

  • struct rio_net *net: RIO network to run on

Description

Marks the component tag CSR on each device with the enumeration complete flag. When complete, it then release the host locks on each device. Returns 0 on success or -EINVAL on failure.

rio_enum_host() #

int rio_enum_host(struct rio_mport *port)

Set host lock and initialize host destination ID

Parameters

  • struct rio_mport *port: Master port to issue transaction

Description

Sets the local host master port lock and destination ID register with the host device ID value. The host device ID value is provided by the platform. Returns 0 on success or -1 on failure.

rio_device_has_destid() #

int rio_device_has_destid(struct rio_mport *port, int src_ops, int dst_ops)

Test if a device contains a destination ID register

Parameters

  • struct rio_mport *port: Master port to issue transaction
  • int src_ops: RIO device source operations
  • int dst_ops: RIO device destination operations

Description

Checks the provided src_ops and dst_ops for the necessary transaction capabilities that indicate whether or not a device will implement a destination ID register. Returns 1 if true or 0 if false.

rio_release_dev() #

void rio_release_dev(struct device *dev)

Frees a RIO device struct

Parameters

  • struct device *dev: LDM device associated with a RIO device struct

Description

Gets the RIO device struct associated a RIO device struct. The RIO device struct is freed.

rio_is_switch() #

int rio_is_switch(struct rio_dev *rdev)

Tests if a RIO device has switch capabilities

Parameters

  • struct rio_dev *rdev: RIO device

Description

Gets the RIO device Processing Element Features register contents and tests for switch capabilities. Returns 1 if the device is a switch or 0 if it is not a switch. The RIO device struct is freed.

rio_setup_device() #

struct rio_dev * rio_setup_device(struct rio_net *net, struct rio_mport *port, u16 destid, u8 hopcount, int do_enum)

Allocates and sets up a RIO device

Parameters

  • struct rio_net *net: RIO network
  • struct rio_mport *port: Master port to send transactions
  • u16 destid: Current destination ID
  • u8 hopcount: Current hopcount
  • int do_enum: Enumeration/Discovery mode flag

Description

Allocates a RIO device and configures fields based on configuration space contents. If device has a destination ID register, a destination ID is either assigned in enumeration mode or read from configuration space in discovery mode. If the device has switch capabilities, then a switch is allocated and configured appropriately. Returns a pointer to a RIO device on success or NULL on failure.

rio_sport_is_active() #

int rio_sport_is_active(struct rio_dev *rdev, int sp)

Tests if a switch port has an active connection.

Parameters

  • struct rio_dev *rdev: RapidIO device object
  • int sp: Switch port number

Description

Reads the port error status CSR for a particular switch port to determine if the port has an active link. Returns RIO_PORT_N_ERR_STS_PORT_OK if the port is active or 0 if it is inactive.

rio_get_host_deviceid_lock() #

u16 rio_get_host_deviceid_lock(struct rio_mport *port, u8 hopcount)

Reads the Host Device ID Lock CSR on a device

Parameters

  • struct rio_mport *port: Master port to send transaction
  • u8 hopcount: Number of hops to the device

Description

Used during enumeration to read the Host Device ID Lock CSR on a RIO device. Returns the value of the lock register.

rio_enum_peer() #

int rio_enum_peer(struct rio_net *net, struct rio_mport *port, u8 hopcount, struct rio_dev *prev, int prev_port)

Recursively enumerate a RIO network through a master port

Parameters

  • struct rio_net *net: RIO network being enumerated
  • struct rio_mport *port: Master port to send transactions
  • u8 hopcount: Number of hops into the network
  • struct rio_dev *prev: Previous RIO device connected to the enumerated one
  • int prev_port: Port on previous RIO device

Description

Recursively enumerates a RIO network. Transactions are sent via the master port passed in port.

rio_enum_complete() #

int rio_enum_complete(struct rio_mport *port)

Tests if enumeration of a network is complete

Parameters

  • struct rio_mport *port: Master port to send transaction

Description

Tests the PGCCSR discovered bit for non-zero value (enumeration complete flag). Return 1 if enumeration is complete or 0 if enumeration is incomplete.

rio_disc_peer() #

int rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid, u8 hopcount, struct rio_dev *prev, int prev_port)

Recursively discovers a RIO network through a master port

Parameters

  • struct rio_net *net: RIO network being discovered
  • struct rio_mport *port: Master port to send transactions
  • u16 destid: Current destination ID in network
  • u8 hopcount: Number of hops into the network
  • struct rio_dev *prev: previous rio_dev
  • int prev_port: previous port number

Description

Recursively discovers a RIO network. Transactions are sent via the master port passed in port.

rio_mport_is_active() #

int rio_mport_is_active(struct rio_mport *port)

Tests if master port link is active

Parameters

  • struct rio_mport *port: Master port to test

Description

Reads the port error status CSR for the master port to determine if the port has an active link. Returns RIO_PORT_N_ERR_STS_PORT_OK if the master port is active or 0 if it is inactive.

rio_update_route_tables() #

void rio_update_route_tables(struct rio_net *net)

Updates route tables in switches

Parameters

  • struct rio_net *net: RIO network to run update on

Description

For each enumerated device, ensure that each switch in a system has correct routing entries. Add routes for devices that where unknown during the first enumeration pass through the switch.

rio_init_em() #

void rio_init_em(struct rio_dev *rdev)

Initializes RIO Error Management (for switches)

Parameters

  • struct rio_dev *rdev: RIO device

Description

For each enumerated switch, call device-specific error management initialization routine (if supplied by the switch driver).

rio_enum_mport() #

int rio_enum_mport(struct rio_mport *mport, u32 flags)

Start enumeration through a master port

Parameters

  • struct rio_mport *mport: Master port to send transactions
  • u32 flags: Enumeration control flags

Description

Starts the enumeration process. If somebody has enumerated our master port device, then give up. If not and we have an active link, then start recursive peer enumeration. Returns 0 if enumeration succeeds or -EBUSY if enumeration fails.

rio_build_route_tables() #

void rio_build_route_tables(struct rio_net *net)

Generate route tables from switch route entries

Parameters

  • struct rio_net *net: RIO network to run route tables scan on

Description

For each switch device, generate a route table by copying existing route entries from the switch.

rio_disc_mport() #

int rio_disc_mport(struct rio_mport *mport, u32 flags)

Start discovery through a master port

Parameters

  • struct rio_mport *mport: Master port to send transactions
  • u32 flags: discovery control flags

Description

Starts the discovery process. If we have an active link, then wait for the signal that enumeration is complete (if wait is allowed). When enumeration completion is signaled, start recursive peer discovery. Returns 0 if discovery succeeds or -EBUSY on failure.

rio_basic_attach() #

int rio_basic_attach(void)

Parameters

  • void: no arguments

Description

When this enumeration/discovery method is loaded as a module this function registers its specific enumeration and discover routines for all available RapidIO mport devices. The "scan" command line parameter controls ability of the module to start RapidIO enumeration/discovery automatically.

Returns 0 for success or -EIO if unable to register itself.

This enumeration/discovery method cannot be unloaded and therefore does not provide a matching cleanup_module routine.

Driver functionality #

rio_setup_inb_dbell() #

int rio_setup_inb_dbell(struct rio_mport *mport, void *dev_id, struct resource *res, void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src, u16 dst, u16 info))

bind inbound doorbell callback

Parameters

  • struct rio_mport *mport: RIO master port to bind the doorbell callback
  • void *dev_id: Device specific pointer to pass on event
  • struct resource *res: Doorbell message resource
  • void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src, u16 dst, u16 info): Callback to execute when doorbell is received

Description

Adds a doorbell resource/callback pair into a port's doorbell event list. Returns 0 if the request has been satisfied.

rio_chk_dev_route() #

int rio_chk_dev_route(struct rio_dev *rdev, struct rio_dev **nrdev, int *npnum)

Validate route to the specified device.

Parameters

  • struct rio_dev *rdev: RIO device failed to respond
  • struct rio_dev **nrdev: Last active device on the route to rdev
  • int *npnum: nrdev's port number on the route to rdev

Description

Follows a route to the specified RIO device to determine the last available device (and corresponding RIO port) on the route.

rio_chk_dev_access() #

int rio_chk_dev_access(struct rio_dev *rdev)

Validate access to the specified device.

Parameters

  • struct rio_dev *rdev: Pointer to RIO device control structure

rio_get_input_status() #

int rio_get_input_status(struct rio_dev *rdev, int pnum, u32 *lnkresp)

Sends a Link-Request/Input-Status control symbol and returns link-response (if requested).

Parameters

  • struct rio_dev *rdev: RIO devive to issue Input-status command
  • int pnum: Device port number to issue the command
  • u32 *lnkresp: Response from a link partner

rio_clr_err_stopped() #

int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status)

Clears port Error-stopped states.

Parameters

  • struct rio_dev *rdev: Pointer to RIO device control structure
  • u32 pnum: Switch port number to clear errors
  • u32 err_status: port error status (if 0 reads register from device)

Description

TODO: Currently this routine is not compatible with recovery process specified for idt_gen3 RapidIO switch devices. It has to be reviewed to implement universal recovery process that is compatible full range off available devices. IDT gen3 switch driver now implements HW-specific error handler that issues soft port reset to the port to reset ERR_STOP bits and ackIDs.

rio_std_route_add_entry() #

int rio_std_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount, u16 table, u16 route_destid, u8 route_port)

Add switch route table entry using standard registers defined in RIO specification rev.1.3

Parameters

  • struct rio_mport *mport: Master port to issue transaction
  • u16 destid: Destination ID of the device
  • u8 hopcount: Number of switch hops to the device
  • u16 table: routing table ID (global or port-specific)
  • u16 route_destid: destID entry in the RT
  • u8 route_port: destination port for specified destID

rio_std_route_get_entry() #

int rio_std_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount, u16 table, u16 route_destid, u8 *route_port)

Read switch route table entry (port number) associated with specified destID using standard registers defined in RIO specification rev.1.3

Parameters

  • struct rio_mport *mport: Master port to issue transaction
  • u16 destid: Destination ID of the device
  • u8 hopcount: Number of switch hops to the device
  • u16 table: routing table ID (global or port-specific)
  • u16 route_destid: destID entry in the RT
  • u8 *route_port: returned destination port for specified destID

rio_std_route_clr_table() #

int rio_std_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount, u16 table)

Clear swotch route table using standard registers defined in RIO specification rev.1.3.

Parameters

  • struct rio_mport *mport: Master port to issue transaction
  • u16 destid: Destination ID of the device
  • u8 hopcount: Number of switch hops to the device
  • u16 table: routing table ID (global or port-specific)

rio_mport_scan() #

int rio_mport_scan(int mport_id)

execute enumeration/discovery on the specified mport

Parameters

  • int mport_id: number (ID) of mport device

RIO_LOP_READ() #

RIO_LOP_READ(size, type, len)

Generate rio_local_read_config_* functions

Parameters

  • size: Size of configuration space read (8, 16, 32 bits)
  • type: C type of value argument
  • len: Length of configuration space read (1, 2, 4 bytes)

Description

Generates rio_local_read_config_* functions used to access configuration space registers on the local device.

RIO_LOP_WRITE() #

RIO_LOP_WRITE(size, type, len)

Generate rio_local_write_config_* functions

Parameters

  • size: Size of configuration space write (8, 16, 32 bits)
  • type: C type of value argument
  • len: Length of configuration space write (1, 2, 4 bytes)

Description

Generates rio_local_write_config_* functions used to access configuration space registers on the local device.

RIO_OP_READ() #

RIO_OP_READ(size, type, len)

Generate rio_mport_read_config_* functions

Parameters

  • size: Size of configuration space read (8, 16, 32 bits)
  • type: C type of value argument
  • len: Length of configuration space read (1, 2, 4 bytes)

Description

Generates rio_mport_read_config_* functions used to access configuration space registers on the local device.

RIO_OP_WRITE() #

RIO_OP_WRITE(size, type, len)

Generate rio_mport_write_config_* functions

Parameters

  • size: Size of configuration space write (8, 16, 32 bits)
  • type: C type of value argument
  • len: Length of configuration space write (1, 2, 4 bytes)

Description

Generates rio_mport_write_config_* functions used to access configuration space registers on the local device.

Device model support #

rio_match_device() #

const struct rio_device_id * rio_match_device(const struct rio_device_id *id, const struct rio_dev *rdev)

Tell if a RIO device has a matching RIO device id structure

Parameters

  • const struct rio_device_id *id: the RIO device id structure to match against
  • const struct rio_dev *rdev: the RIO device structure to match against

Description

Used from driver probe and bus matching to check whether a RIO device matches a device id structure provided by a RIO driver. Returns the matching struct rio_device_id or NULL if there is no match.

rio_device_probe() #

int rio_device_probe(struct device *dev)

Tell if a RIO device structure has a matching RIO device id structure

Parameters

  • struct device *dev: the RIO device structure to match against

Description

return 0 and set rio_dev->driver when drv claims rio_dev, else error

rio_device_remove() #

void rio_device_remove(struct device *dev)

Remove a RIO device from the system

Parameters

  • struct device *dev: the RIO device structure to match against

Description

Remove a RIO device from the system. If it has an associated driver, then run the driver remove() method. Then update the reference count.

rio_match_bus() #

int rio_match_bus(struct device *dev, const struct device_driver *drv)

Tell if a RIO device structure has a matching RIO driver device id structure

Parameters

  • struct device *dev: the standard device structure to match against
  • const struct device_driver *drv: the standard driver structure containing the ids to match against

Description

Used by a driver to check whether a RIO device present in the system is in its list of supported devices. Returns 1 if there is a matching struct rio_device_id or 0 if there is no match.

rio_bus_init() #

int rio_bus_init(void)

Register the RapidIO bus with the device model

Parameters

  • void: no arguments

Description

Registers the RIO mport device class and RIO bus type with the Linux device model.

PPC32 support #

fsl_local_config_read() #

int fsl_local_config_read(struct rio_mport *mport, int index, u32 offset, int len, u32 *data)

Generate a MPC85xx local config space read

Parameters

  • struct rio_mport *mport: RapidIO master port info
  • int index: ID of RapdiIO interface
  • u32 offset: Offset into configuration space
  • int len: Length (in bytes) of the maintenance transaction
  • u32 *data: Value to be read into

Description

Generates a MPC85xx local configuration space read. Returns 0 on success or -EINVAL on failure.

fsl_local_config_write() #

int fsl_local_config_write(struct rio_mport *mport, int index, u32 offset, int len, u32 data)

Generate a MPC85xx local config space write

Parameters

  • struct rio_mport *mport: RapidIO master port info
  • int index: ID of RapdiIO interface
  • u32 offset: Offset into configuration space
  • int len: Length (in bytes) of the maintenance transaction
  • u32 data: Value to be written

Description

Generates a MPC85xx local configuration space write. Returns 0 on success or -EINVAL on failure.

fsl_rio_config_read() #

int fsl_rio_config_read(struct rio_mport *mport, int index, u16 destid, u8 hopcount, u32 offset, int len, u32 *val)

Generate a MPC85xx read maintenance transaction

Parameters

  • struct rio_mport *mport: RapidIO master port info
  • int index: ID of RapdiIO interface
  • u16 destid: Destination ID of transaction
  • u8 hopcount: Number of hops to target device
  • u32 offset: Offset into configuration space
  • int len: Length (in bytes) of the maintenance transaction
  • u32 *val: Location to be read into

Description

Generates a MPC85xx read maintenance transaction. Returns 0 on success or -EINVAL on failure.

fsl_rio_config_write() #

int fsl_rio_config_write(struct rio_mport *mport, int index, u16 destid, u8 hopcount, u32 offset, int len, u32 val)

Generate a MPC85xx write maintenance transaction

Parameters

  • struct rio_mport *mport: RapidIO master port info
  • int index: ID of RapdiIO interface
  • u16 destid: Destination ID of transaction
  • u8 hopcount: Number of hops to target device
  • u32 offset: Offset into configuration space
  • int len: Length (in bytes) of the maintenance transaction
  • u32 val: Value to be written

Description

Generates an MPC85xx write maintenance transaction. Returns 0 on success or -EINVAL on failure.

fsl_rio_setup() #

int fsl_rio_setup(struct platform_device *dev)

Setup Freescale PowerPC RapidIO interface

Parameters

  • struct platform_device *dev: platform_device pointer

Description

Initializes MPC85xx RapidIO hardware interface, configures master port with system-specific info, and registers the master port with the RapidIO subsystem.

Credits #

The following people have contributed to the RapidIO subsystem directly or indirectly:

  1. Matt Portermporter@kernel.crashing.org

  2. Randy Vinsonrvinson@mvista.com

  3. Dan Malekdan@embeddedalley.com

The following people have contributed to this document:

  1. Matt Portermporter@kernel.crashing.org

Real Time Clock (RTC) Drivers for Linux

Peios Kernel / Administration / System administration / Device configuration

Peios: Interrupt frequencies above the configured user limit require CAP_SYS_RESOURCE, mapped to SeIncreaseQuotaPrivilege; setting the clock requires CAP_SYS_TIME, mapped to SeSystemtimePrivilege. Native device access still applies. See Peios kernel behaviour.

When Linux developers talk about a "Real Time Clock", they usually mean something that tracks wall clock time and is battery backed so that it works even with system power off. Such clocks will normally not track the local time zone or daylight savings time -- unless they dual boot with MS-Windows -- but will instead be set to Coordinated Universal Time (UTC, formerly "Greenwich Mean Time").

The newest non-PC hardware tends to just count seconds, like the time(2) system call reports, but RTCs also very commonly represent time using the Gregorian calendar and 24 hour time, as reported by gmtime(3).

Linux has two largely-compatible userspace RTC API families you may need to know about:

  • /dev/rtc ... is the RTC provided by PC compatible systems, so it's not very portable to non-x86 systems.

  • /dev/rtc0, /dev/rtc1 ... are part of a framework that's supported by a wide variety of RTC chips on all systems.

Programmers need to understand that the PC/AT functionality is not always available, and some systems can do much more. That is, the RTCs use the same API to make requests in both RTC frameworks (using different filenames of course), but the hardware may not offer the same functionality. For example, not every RTC is hooked up to an IRQ, so they can't all issue alarms; and where standard PC RTCs can only issue an alarm up to 24 hours in the future, other hardware may be able to schedule one any time in the upcoming century.

Old PC/AT-Compatible driver: /dev/rtc #

All PCs (even Alpha machines) have a Real Time Clock built into them. Usually they are built into the chipset of the computer, but some may actually have a Motorola MC146818 (or clone) on the board. This is the clock that keeps the date and time while your computer is turned off.

ACPI has standardized that MC146818 functionality, and extended it in a few ways (enabling longer alarm periods, and wake-from-hibernate). That functionality is NOT exposed in the old driver.

However it can also be used to generate signals from a slow 2Hz to a relatively fast 8192Hz, in increments of powers of two. These signals are reported by interrupt number 8. (Oh! So that is what IRQ 8 is for...) It can also function as a 24hr alarm, raising IRQ 8 when the alarm goes off. The alarm can also be programmed to only check any subset of the three programmable values, meaning that it could be set to ring on the 30th second of the 30th minute of every hour, for example. The clock can also be set to generate an interrupt upon every clock update, thus generating a 1Hz signal.

The interrupts are reported via /dev/rtc (major 10, minor 135, read only character device) in the form of an unsigned long. The low byte contains the type of interrupt (update-done, alarm-rang, or periodic) that was raised, and the remaining bytes contain the number of interrupts since the last read. Status information is reported through the pseudo-file /proc/driver/rtc if the /proc filesystem was enabled. The driver has built in locking so that only one process is allowed to have the /dev/rtc interface open at a time.

A user process can monitor these interrupts by doing a read(2) or a select(2) on /dev/rtc -- either will block/stop the user process until the next interrupt is received. This is useful for things like reasonably high frequency data acquisition where one doesn't want to burn up 100% CPU by polling gettimeofday etc. etc.

At high frequencies, or under high loads, the user process should check the number of interrupts received since the last read to determine if there has been any interrupt "pileup" so to speak. Just for reference, a typical 486-33 running a tight read loop on /dev/rtc will start to suffer occasional interrupt pileup (i.e. > 1 IRQ event since last read) for frequencies above 1024Hz. So you really should check the high bytes of the value you read, especially at frequencies above that of the normal timer interrupt, which is 100Hz.

Programming and/or enabling interrupt frequencies greater than 64Hz is only allowed by root. This is perhaps a bit conservative, but we don't want an evil user generating lots of IRQs on a slow 386sx-16, where it might have a negative impact on performance. This 64Hz limit can be changed by writing a different value to /proc/sys/dev/rtc/max-user-freq. Note that the interrupt handler is only a few lines of code to minimize any possibility of this effect.

Also, if the kernel time is synchronized with an external source, the kernel will write the time back to the CMOS clock every 11 minutes. In the process of doing this, the kernel briefly turns off RTC periodic interrupts, so be aware of this if you are doing serious work. If you don't synchronize the kernel time with an external source (via ntp or whatever) then the kernel will keep its hands off the RTC, allowing you exclusive access to the device for your applications.

The alarm and/or interrupt frequency are programmed into the RTC via various ioctl(2) calls as listed in ./include/linux/rtc.h Rather than write 50 pages describing the ioctl() and so on, it is perhaps more useful to include a small test program that demonstrates how to use them, and demonstrates the features of the driver. This is probably a lot more useful to people interested in writing applications that will be using this driver. See the code at the end of this document.

(The original /dev/rtc driver was written by Paul Gortmaker.)

New portable "RTC Class" drivers: /dev/rtcN #

Because Linux supports many non-ACPI and non-PC platforms, some of which have more than one RTC style clock, it needed a more portable solution than expecting a single battery-backed MC146818 clone on every system. Accordingly, a new "RTC Class" framework has been defined. It offers three different userspace interfaces:

  • /dev/rtcN ... much the same as the older /dev/rtc interface

  • /sys/class/rtc/rtcN ... sysfs attributes support readonly access to some RTC attributes.

  • /proc/driver/rtc ... the system clock RTC may expose itself using a procfs interface. If there is no RTC for the system clock, rtc0 is used by default. More information is (currently) shown here than through sysfs.

The RTC Class framework supports a wide variety of RTCs, ranging from those integrated into embeddable system-on-chip (SOC) processors to discrete chips using I2C, SPI, or some other bus to communicate with the host CPU. There's even support for PC-style RTCs ... including the features exposed on newer PCs through ACPI.

The new framework also removes the "one RTC per system" restriction. For example, maybe the low-power battery-backed RTC is a discrete I2C chip, but a high functionality RTC is integrated into the SOC. That system might read the system clock from the discrete RTC, but use the integrated one for all other tasks, because of its greater functionality.

Check out tools/testing/selftests/rtc/rtctest.c for an example usage of the ioctl interface.

USB4 and Thunderbolt

Peios Kernel / Administration / System administration / Device configuration

USB4 is the public specification based on Thunderbolt 3 protocol with some differences at the register level among other things. Connection manager is an entity running on the host router (host controller) responsible for enumerating routers and establishing tunnels. A connection manager can be implemented either in firmware or software. Typically PCs come with a firmware connection manager for Thunderbolt 3 and early USB4 capable systems. Apple systems on the other hand use software connection manager and the later USB4 compliant devices follow the suit.

The Linux Thunderbolt driver supports both and can detect at runtime which connection manager implementation is to be used. To be on the safe side the software connection manager in Linux also advertises security level user which means PCIe tunneling is disabled by default. The documentation below applies to both implementations with the exception that the software connection manager only supports user security level and is expected to be accompanied with an IOMMU based DMA protection.

Security levels and how to use them #

The interface presented here is not meant for end users. Instead there should be a userspace tool that handles all the low-level details, keeps a database of the authorized devices and prompts users for new connections.

More details about the sysfs interface for Thunderbolt devices can be found in Documentation/ABI/testing/sysfs-bus-thunderbolt.

Those users who just want to connect any device without any sort of manual work can add following line to /etc/udev/rules.d/99-local.rules:

ACTION=="add", SUBSYSTEM=="thunderbolt", ATTR{authorized}=="0", ATTR{authorized}="1"

This will authorize all devices automatically when they appear. However, keep in mind that this bypasses the security levels and makes the system vulnerable to DMA attacks.

Starting with Intel Falcon Ridge Thunderbolt controller there are 4 security levels available. Intel Titan Ridge added one more security level (usbonly). The reason for these is the fact that the connected devices can be DMA masters and thus read contents of the host memory without CPU and OS knowing about it. There are ways to prevent this by setting up an IOMMU but it is not always available for various reasons.

Some USB4 systems have a BIOS setting to disable PCIe tunneling. This is treated as another security level (nopcie).

The security levels are as follows:

  • none

    All devices are automatically connected by the firmware. No user approval is needed. In BIOS settings this is typically called Legacy mode.

  • user

    User is asked whether the device is allowed to be connected. Based on the device identification information available through /sys/bus/thunderbolt/devices, the user then can make the decision. In BIOS settings this is typically called Unique ID.

  • secure

    User is asked whether the device is allowed to be connected. In addition to UUID the device (if it supports secure connect) is sent a challenge that should match the expected one based on a random key written to the key sysfs attribute. In BIOS settings this is typically called One time saved key.

  • dponly

    The firmware automatically creates tunnels for Display Port and USB. No PCIe tunneling is done. In BIOS settings this is typically called Display Port Only.

  • usbonly

    The firmware automatically creates tunnels for the USB controller and Display Port in a dock. All PCIe links downstream of the dock are removed.

  • nopcie

    PCIe tunneling is disabled/forbidden from the BIOS. Available in some USB4 systems.

The current security level can be read from /sys/bus/thunderbolt/devices/domainX/security where domainX is the Thunderbolt domain the host controller manages. There is typically one domain per Thunderbolt host controller.

If the security level reads as user or secure the connected device must be authorized by the user before PCIe tunnels are created (e.g the PCIe device appears).

Each Thunderbolt device plugged in will appear in sysfs under /sys/bus/thunderbolt/devices. The device directory carries information that can be used to identify the particular device, including its name and UUID.

Authorizing devices when security level is user or secure #

When a device is plugged in it will appear in sysfs as follows:

/sys/bus/thunderbolt/devices/0-1/authorized   - 0
/sys/bus/thunderbolt/devices/0-1/device       - 0x8004
/sys/bus/thunderbolt/devices/0-1/device_name  - Thunderbolt to FireWire Adapter
/sys/bus/thunderbolt/devices/0-1/vendor       - 0x1
/sys/bus/thunderbolt/devices/0-1/vendor_name  - Apple, Inc.
/sys/bus/thunderbolt/devices/0-1/unique_id    - e0376f00-0300-0100-ffff-ffffffffffff

The authorized attribute reads 0 which means no PCIe tunnels are created yet. The user can authorize the device by simply entering:

# echo 1 > /sys/bus/thunderbolt/devices/0-1/authorized

This will create the PCIe tunnels and the device is now connected.

If the device supports secure connect, and the domain security level is set to secure, it has an additional attribute key which can hold a random 32-byte value used for authorization and challenging the device in future connects:

/sys/bus/thunderbolt/devices/0-3/authorized   - 0
/sys/bus/thunderbolt/devices/0-3/device       - 0x305
/sys/bus/thunderbolt/devices/0-3/device_name  - AKiTiO Thunder3 PCIe Box
/sys/bus/thunderbolt/devices/0-3/key          -
/sys/bus/thunderbolt/devices/0-3/vendor       - 0x41
/sys/bus/thunderbolt/devices/0-3/vendor_name  - inXtron
/sys/bus/thunderbolt/devices/0-3/unique_id    - dc010000-0000-8508-a22d-32ca6421cb16

Notice the key is empty by default.

If the user does not want to use secure connect they can just echo 1 to the authorized attribute and the PCIe tunnels will be created in the same way as in the user security level.

If the user wants to use secure connect, the first time the device is plugged a key needs to be created and sent to the device:

# key=$(openssl rand -hex 32)
# echo $key > /sys/bus/thunderbolt/devices/0-3/key
# echo 1 > /sys/bus/thunderbolt/devices/0-3/authorized

Now the device is connected (PCIe tunnels are created) and in addition the key is stored on the device NVM.

Next time the device is plugged in the user can verify (challenge) the device using the same key:

# echo $key > /sys/bus/thunderbolt/devices/0-3/key
# echo 2 > /sys/bus/thunderbolt/devices/0-3/authorized

If the challenge the device returns back matches the one we expect based on the key, the device is connected and the PCIe tunnels are created. However, if the challenge fails no tunnels are created and error is returned to the user.

If the user still wants to connect the device they can either approve the device without a key or write a new key and write 1 to the authorized file to get the new key stored on the device NVM.

De-authorizing devices #

It is possible to de-authorize devices by writing 0 to their authorized attribute. This requires support from the connection manager implementation and can be checked by reading domain deauthorization attribute. If it reads 1 then the feature is supported.

When a device is de-authorized the PCIe tunnel from the parent device PCIe downstream (or root) port to the device PCIe upstream port is torn down. This is essentially the same thing as PCIe hot-remove and the PCIe toplogy in question will not be accessible anymore until the device is authorized again. If there is storage such as NVMe or similar involved, there is a risk for data loss if the filesystem on that storage is not properly shut down. You have been warned!

DMA protection utilizing IOMMU #

Recent systems from 2018 and forward with Thunderbolt ports may natively support IOMMU. This means that Thunderbolt security is handled by an IOMMU so connected devices cannot access memory regions outside of what is allocated for them by drivers. When Linux is running on such system it automatically enables IOMMU if not enabled by the user already. These systems can be identified by reading 1 from /sys/bus/thunderbolt/devices/domainX/iommu_dma_protection attribute.

The driver does not do anything special in this case but because DMA protection is handled by the IOMMU, security levels (if set) are redundant. For this reason some systems ship with security level set to none. Other systems have security level set to user in order to support downgrade to older OS, so users who want to automatically authorize devices when IOMMU DMA protection is enabled can use the following udev rule:

ACTION=="add", SUBSYSTEM=="thunderbolt", ATTRS{iommu_dma_protection}=="1", ATTR{authorized}=="0", ATTR{authorized}="1"

Upgrading NVM on Thunderbolt device, host or retimer #

Since most of the functionality is handled in firmware running on a host controller or a device, it is important that the firmware can be upgraded to the latest where possible bugs in it have been fixed. Typically OEMs provide this firmware from their support site.

Currently, recommended method of updating firmware is through "fwupd" tool. It uses LVFS (Linux Vendor Firmware Service) portal by default to get the latest firmware from hardware vendors and updates connected devices if found compatible. For details refer to: https://github.com/fwupd/fwupd.

Before you upgrade firmware on a device, host or retimer, please make sure it is a suitable upgrade. Failing to do that may render the device in a state where it cannot be used properly anymore without special tools!

Host NVM upgrade on Apple Macs is not supported.

Fwupd is installed by default. If you don't have it on your system, simply use your distro package manager to get it.

To see possible updates through fwupd, you need to plug in a Thunderbolt device so that the host controller appears. It does not matter which device is connected (unless you are upgrading NVM on a device - then you need to connect that particular device).

Note an OEM-specific method to power the controller up ("force power") may be available for your system in which case there is no need to plug in a Thunderbolt device.

Updating firmware using fwupd is straightforward - refer to official readme on fwupd github.

If firmware image is written successfully, the device shortly disappears. Once it comes back, the driver notices it and initiates a full power cycle. After a while device appears again and this time it should be fully functional.

Device of interest should display new version under "Current version" and "Update State: Success" in fwupd's interface.

Upgrading firmware manually #

If possible, use fwupd to updated the firmware. However, if your device OEM has not uploaded the firmware to LVFS, but it is available for download from their side, you can use method below to directly upgrade the firmware.

Manual firmware update can be done with 'dd' tool. To update firmware using this method, you need to write it to the non-active parts of NVM of the host or device. Example on how to update Intel NUC6i7KYK (Skull Canyon) Thunderbolt controller NVM:

# dd if=KYK_TBT_FW_0018.bin of=/sys/bus/thunderbolt/devices/0-0/nvm_non_active0/nvmem

Once the operation completes we can trigger NVM authentication and upgrade process as follows:

# echo 1 > /sys/bus/thunderbolt/devices/0-0/nvm_authenticate

If no errors are returned, device should behave as described in previous section.

We can verify that the new NVM firmware is active by running the following commands:

# cat /sys/bus/thunderbolt/devices/0-0/nvm_authenticate
0x0
# cat /sys/bus/thunderbolt/devices/0-0/nvm_version
18.0

If nvm_authenticate contains anything other than 0x0 it is the error code from the last authentication cycle, which means the authentication of the NVM image failed.

Note names of the NVMem devices nvm_activeN and nvm_non_activeN depend on the order they are registered in the NVMem subsystem. N in the name is the identifier added by the NVMem subsystem.

Upgrading on-board retimer NVM when there is no cable connected #

If the platform supports, it may be possible to upgrade the retimer NVM firmware even when there is nothing connected to the USB4 ports. When this is the case the usb4_portX devices have two special attributes: offline and rescan. The way to upgrade the firmware is to first put the USB4 port into offline mode:

# echo 1 > /sys/bus/thunderbolt/devices/0-0/usb4_port1/offline

This step makes sure the port does not respond to any hotplug events, and also ensures the retimers are powered on. The next step is to scan for the retimers:

# echo 1 > /sys/bus/thunderbolt/devices/0-0/usb4_port1/rescan

This enumerates and adds the on-board retimers. Now retimer NVM can be upgraded in the same way than with cable connected (see previous section). However, the retimer is not disconnected as we are offline mode) so after writing 1 to nvm_authenticate one should wait for 5 or more seconds before running rescan again:

# echo 1 > /sys/bus/thunderbolt/devices/0-0/usb4_port1/rescan

This point if everything went fine, the port can be put back to functional state again:

# echo 0 > /sys/bus/thunderbolt/devices/0-0/usb4_port1/offline

Upgrading NVM when host controller is in safe mode #

If the existing NVM is not properly authenticated (or is missing) the host controller goes into safe mode which means that the only available functionality is flashing a new NVM image. When in this mode, reading nvm_version fails with ENODATA and the device identification information is missing.

To recover from this mode, one needs to flash a valid NVM image to the host controller in the same way it is done in the previous chapter.

Tunneling events #

The driver sends KOBJ_CHANGE events to userspace when there is a tunneling change in the thunderbolt_domain. The notification carries following environment variables:

TUNNEL_EVENT=<EVENT>
TUNNEL_DETAILS=0:12 <-> 1:20 (USB3)

Possible values for <EVENT> are:

  • activated

    The tunnel was activated (created).

  • changed

    There is a change in this tunnel. For example bandwidth allocation was changed.

  • deactivated

    The tunnel was torn down.

  • low bandwidth

    The tunnel is not getting optimal bandwidth.

  • insufficient bandwidth

    There is not enough bandwidth for the current tunnel requirements.

The TUNNEL_DETAILS is only provided if the tunnel is known. For example, in case of Firmware Connection Manager this is missing or does not provide full tunnel information. In case of Software Connection Manager this includes full tunnel details. The format currently matches what the driver uses when logging. This may change over time.

Networking over Thunderbolt cable #

Thunderbolt technology allows software communication between two hosts connected by a Thunderbolt cable.

It is possible to tunnel any kind of traffic over a Thunderbolt link but currently we only support Apple ThunderboltIP protocol.

If the other host is running Windows or macOS, the only thing you need to do is to connect a Thunderbolt cable between the two hosts; the thunderbolt-net driver is loaded automatically. If the other host is also Linux you should load thunderbolt-net manually on one host (it does not matter which one):

# modprobe thunderbolt-net

This triggers module load on the other host automatically. If the driver is built-in to the kernel image, there is no need to do anything.

The driver will create one virtual ethernet interface per Thunderbolt port which are named like thunderbolt0 and so on. From this point you can either use standard userspace tools like ip to configure the interface or let your GUI handle it automatically.

Forcing power #

Many OEMs include a method that can be used to force the power of a Thunderbolt controller to an "On" state even if nothing is connected. If supported by your machine this will be exposed by the WMI bus with a sysfs attribute called "force_power", see Documentation/ABI/testing/sysfs-platform-intel-wmi-thunderbolt for details.

Note: it's currently not possible to query the force power state of a platform.

Peios Learn — documentation for Peios software.

Built with Trail.