08f7c9baaf5fad76a1fcf1f9a7a41448ed16d72e
[deb_dpdk.git] / doc / guides / linux_gsg / linux_drivers.rst
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
34 Linux Drivers
35 =============
36
37 Different PMDs may require different kernel drivers in order to work properly.
38 Depends on the PMD being used, a corresponding kernel driver should be load
39 and bind to the network ports.
40
41 UIO
42 ---
43
44 A small kernel module to set up the device, map device memory to user-space and register interrupts.
45 In many cases, the standard ``uio_pci_generic`` module included in the Linux kernel
46 can 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
56 As an alternative to the ``uio_pci_generic``, the DPDK also includes the igb_uio
57 module which can be found in the kmod subdirectory referred to above. It can
58 be 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
77 Since DPDK release 1.7 onward provides VFIO support, use of UIO is optional
78 for platforms that support using VFIO.
79
80 VFIO
81 ----
82
83 A more robust and secure driver in compare to the ``UIO``, relying on IOMMU protection.
84 To make use of VFIO, the ``vfio-pci`` module must be loaded:
85
86 .. code-block:: console
87
88     sudo modprobe vfio-pci
89
90 Note that in order to use VFIO, your kernel must support it.
91 VFIO kernel modules have been included in the Linux kernel since version 3.6.0 and are usually present by default,
92 however please consult your distributions documentation to make sure that is the case.
93
94 Also, 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
100 For proper operation of VFIO when running DPDK applications as a non-privileged user, correct permissions should also be set up.
101 This 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
107 Bifurcated Driver
108 -----------------
109
110 PMDs which use the bifurcated driver co-exists with the device kernel driver.
111 On such model the NIC is controlled by the kernel, while the data
112 path is performed by the PMD directly on top of the device.
113
114 Such 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
123 More 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
129 Binding 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
136 As of release 1.4, DPDK applications no longer automatically unbind all supported network ports from the kernel driver in use.
137 Instead, 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.
139 For such PMDs, any network ports under Linux* control will be ignored and cannot be used by the application.
140
141 To bind ports to the ``uio_pci_generic``, ``igb_uio`` or ``vfio-pci`` module for DPDK use,
142 and then subsequently return ports to Linux* control,
143 a utility script called dpdk-devbind.py is provided in the usertools subdirectory.
144 This utility can be used to provide a view of the current state of the network ports on the system,
145 and to bind and unbind those ports from the different kernel modules, including the uio and vfio modules.
146 The following are some examples of how the script can be used.
147 A full description of the script and its parameters can be obtained by calling the script with the ``--help`` or ``--usage`` options.
148 Note that the uio or vfio kernel modules to be used, should be loaded into the kernel before
149 running 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
166 To 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
188 To 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
194 or, alternatively,
195
196 .. code-block:: console
197
198     ./usertools/dpdk-devbind.py --bind=uio_pci_generic eth1
199
200 To 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