xref: /dpdk/doc/guides/linux_gsg/linux_drivers.rst (revision f8244c6399d9fae6afab6770ae367aef38742ea5)
1..  BSD LICENSE
2    Copyright(c) 2010-2015 Intel Corporation.
3    Copyright(c) 2017 Mellanox Corporation.
4    All rights reserved.
5
6    Redistribution and use in source and binary forms, with or without
7    modification, are permitted provided that the following conditions
8    are met:
9
10    * Redistributions of source code must retain the above copyright
11    notice, this list of conditions and the following disclaimer.
12    * Redistributions in binary form must reproduce the above copyright
13    notice, this list of conditions and the following disclaimer in
14    the documentation and/or other materials provided with the
15    distribution.
16    * Neither the name of Intel Corporation nor the names of its
17    contributors may be used to endorse or promote products derived
18    from this software without specific prior written permission.
19
20    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32.. _linux_gsg_linux_drivers:
33
34Linux Drivers
35=============
36
37Different PMDs may require different kernel drivers in order to work properly.
38Depends on the PMD being used, a corresponding kernel driver should be load
39and bind to the network ports.
40
41UIO
42---
43
44A small kernel module to set up the device, map device memory to user-space and register interrupts.
45In many cases, the standard ``uio_pci_generic`` module included in the Linux kernel
46can provide the uio capability. This module can be loaded using the command:
47
48.. code-block:: console
49
50    sudo modprobe uio_pci_generic
51
52.. note::
53
54    ``uio_pci_generic`` module doesn't support the creation of virtual functions.
55
56As an alternative to the ``uio_pci_generic``, the DPDK also includes the igb_uio
57module which can be found in the kmod subdirectory referred to above. It can
58be loaded as shown below:
59
60.. code-block:: console
61
62    sudo modprobe uio
63    sudo insmod kmod/igb_uio.ko
64
65.. note::
66
67    For some devices which lack support for legacy interrupts, e.g. virtual function
68    (VF) devices, the ``igb_uio`` module may be needed in place of ``uio_pci_generic``.
69
70.. note::
71
72   If UEFI secure boot is enabled, the Linux kernel may disallow the use of
73   UIO on the system. Therefore, devices for use by DPDK should be bound to the
74   ``vfio-pci`` kernel module rather than ``igb_uio`` or ``uio_pci_generic``.
75   For more details see :ref:`linux_gsg_binding_kernel` below.
76
77Since DPDK release 1.7 onward provides VFIO support, use of UIO is optional
78for platforms that support using VFIO.
79
80VFIO
81----
82
83A more robust and secure driver in compare to the ``UIO``, relying on IOMMU protection.
84To make use of VFIO, the ``vfio-pci`` module must be loaded:
85
86.. code-block:: console
87
88    sudo modprobe vfio-pci
89
90Note that in order to use VFIO, your kernel must support it.
91VFIO kernel modules have been included in the Linux kernel since version 3.6.0 and are usually present by default,
92however please consult your distributions documentation to make sure that is the case.
93
94Also, to use VFIO, both kernel and BIOS must support and be configured to use IO virtualization (such as Intel® VT-d).
95
96.. note::
97
98    ``vfio-pci`` module doesn't support the creation of virtual functions.
99
100For proper operation of VFIO when running DPDK applications as a non-privileged user, correct permissions should also be set up.
101This can be done by using the DPDK setup script (called dpdk-setup.sh and located in the usertools directory).
102
103.. note::
104
105    VFIO can be used without IOMMU. While this is just as unsafe as using UIO, it does make it possible for the user to keep the degree of device access and programming that VFIO has, in situations where IOMMU is not available.
106
107Bifurcated Driver
108-----------------
109
110PMDs which use the bifurcated driver co-exists with the device kernel driver.
111On such model the NIC is controlled by the kernel, while the data
112path is performed by the PMD directly on top of the device.
113
114Such model has the following benefits:
115
116 - It is secure and robust, as the memory management and isolation
117   is done by the kernel.
118 - It enables the user to use legacy linux tools such as ``ethtool`` or
119   ``ifconfig`` while running DPDK application on the same network ports.
120 - It enables the DPDK application to filter only part of the traffic,
121   While the rest will be directed and handled by the kernel driver.
122
123More about the bifurcated driver can be found in
124`Mellanox Bifurcated DPDK PMD
125<https://dpdksummit.com/Archive/pdf/2016Userspace/Day02-Session04-RonyEfraim-Userspace2016.pdf>`__.
126
127.. _linux_gsg_binding_kernel:
128
129Binding and Unbinding Network Ports to/from the Kernel Modules
130--------------------------------------------------------------
131
132.. note::
133
134    PMDs Which use the bifurcated driver should not be unbind from their kernel drivers. this section is for PMDs which use the UIO or VFIO drivers.
135
136As of release 1.4, DPDK applications no longer automatically unbind all supported network ports from the kernel driver in use.
137Instead, in case the PMD being used use the UIO or VFIO drivers, all ports that are to be used by an DPDK application must be bound to the
138``uio_pci_generic``, ``igb_uio`` or ``vfio-pci`` module before the application is run.
139For such PMDs, any network ports under Linux* control will be ignored and cannot be used by the application.
140
141To bind ports to the ``uio_pci_generic``, ``igb_uio`` or ``vfio-pci`` module for DPDK use,
142and then subsequently return ports to Linux* control,
143a utility script called dpdk-devbind.py is provided in the usertools subdirectory.
144This utility can be used to provide a view of the current state of the network ports on the system,
145and to bind and unbind those ports from the different kernel modules, including the uio and vfio modules.
146The following are some examples of how the script can be used.
147A full description of the script and its parameters can be obtained by calling the script with the ``--help`` or ``--usage`` options.
148Note that the uio or vfio kernel modules to be used, should be loaded into the kernel before
149running the ``dpdk-devbind.py`` script.
150
151.. warning::
152
153    Due to the way VFIO works, there are certain limitations to which devices can be used with VFIO.
154    Mainly it comes down to how IOMMU groups work.
155    Any Virtual Function device can be used with VFIO on its own, but physical devices will require either all ports bound to VFIO,
156    or some of them bound to VFIO while others not being bound to anything at all.
157
158    If your device is behind a PCI-to-PCI bridge, the bridge will then be part of the IOMMU group in which your device is in.
159    Therefore, the bridge driver should also be unbound from the bridge PCI device for VFIO to work with devices behind the bridge.
160
161.. warning::
162
163    While any user can run the dpdk-devbind.py script to view the status of the network ports,
164    binding or unbinding network ports requires root privileges.
165
166To see the status of all network ports on the system:
167
168.. code-block:: console
169
170    ./usertools/dpdk-devbind.py --status
171
172    Network devices using DPDK-compatible driver
173    ============================================
174    0000:82:00.0 '82599EB 10-GbE NIC' drv=uio_pci_generic unused=ixgbe
175    0000:82:00.1 '82599EB 10-GbE NIC' drv=uio_pci_generic unused=ixgbe
176
177    Network devices using kernel driver
178    ===================================
179    0000:04:00.0 'I350 1-GbE NIC' if=em0  drv=igb unused=uio_pci_generic *Active*
180    0000:04:00.1 'I350 1-GbE NIC' if=eth1 drv=igb unused=uio_pci_generic
181    0000:04:00.2 'I350 1-GbE NIC' if=eth2 drv=igb unused=uio_pci_generic
182    0000:04:00.3 'I350 1-GbE NIC' if=eth3 drv=igb unused=uio_pci_generic
183
184    Other network devices
185    =====================
186    <none>
187
188To bind device ``eth1``,``04:00.1``, to the ``uio_pci_generic`` driver:
189
190.. code-block:: console
191
192    ./usertools/dpdk-devbind.py --bind=uio_pci_generic 04:00.1
193
194or, alternatively,
195
196.. code-block:: console
197
198    ./usertools/dpdk-devbind.py --bind=uio_pci_generic eth1
199
200To restore device ``82:00.0`` to its original kernel binding:
201
202.. code-block:: console
203
204    ./usertools/dpdk-devbind.py --bind=ixgbe 82:00.0
205