doc: move kernel drivers to a new chapter
[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 Since DPDK release 1.7 onward provides VFIO support, use of UIO is optional
71 for platforms that support using VFIO.
72
73 VFIO
74 ----
75
76 A more robust and secure driver in compare to the ``UIO``, relying on IOMMU protection.
77 To make use of VFIO, the ``vfio-pci`` module must be loaded:
78
79 .. code-block:: console
80
81     sudo modprobe vfio-pci
82
83 Note that in order to use VFIO, your kernel must support it.
84 VFIO kernel modules have been included in the Linux kernel since version 3.6.0 and are usually present by default,
85 however please consult your distributions documentation to make sure that is the case.
86
87 Also, to use VFIO, both kernel and BIOS must support and be configured to use IO virtualization (such as IntelĀ® VT-d).
88
89 .. note::
90
91     ``vfio-pci`` module doesn't support the creation of virtual functions.
92
93 For proper operation of VFIO when running DPDK applications as a non-privileged user, correct permissions should also be set up.
94 This can be done by using the DPDK setup script (called dpdk-setup.sh and located in the usertools directory).
95
96 .. note::
97
98     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.
99
100 Bifurcated Driver
101 -----------------
102
103 PMDs which use the bifurcated driver co-exists with the device kernel driver.
104 On such model the NIC is controlled by the kernel, while the data
105 path is performed by the PMD directly on top of the device.
106
107 Such model has the following benefits:
108
109  - It is secure and robust, as the memory management and isolation
110    is done by the kernel.
111  - It enables the user to use legacy linux tools such as ``ethtool`` or
112    ``ifconfig`` while running DPDK application on the same network ports.
113  - It enables the DPDK application to filter only part of the traffic,
114    While the rest will be directed and handled by the kernel driver.
115
116 More about the bifurcated driver can be found in
117 `Mellanox Bifurcated DPDK PMD
118 <https://dpdksummit.com/Archive/pdf/2016Userspace/Day02-Session04-RonyEfraim-Userspace2016.pdf>`__.
119
120 .. _linux_gsg_binding_kernel:
121
122 Binding and Unbinding Network Ports to/from the Kernel Modules
123 --------------------------------------------------------------
124
125 .. note::
126
127     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.
128
129 As of release 1.4, DPDK applications no longer automatically unbind all supported network ports from the kernel driver in use.
130 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
131 ``uio_pci_generic``, ``igb_uio`` or ``vfio-pci`` module before the application is run.
132 For such PMDs, any network ports under Linux* control will be ignored and cannot be used by the application.
133
134 To bind ports to the ``uio_pci_generic``, ``igb_uio`` or ``vfio-pci`` module for DPDK use,
135 and then subsequently return ports to Linux* control,
136 a utility script called dpdk-devbind.py is provided in the usertools subdirectory.
137 This utility can be used to provide a view of the current state of the network ports on the system,
138 and to bind and unbind those ports from the different kernel modules, including the uio and vfio modules.
139 The following are some examples of how the script can be used.
140 A full description of the script and its parameters can be obtained by calling the script with the ``--help`` or ``--usage`` options.
141 Note that the uio or vfio kernel modules to be used, should be loaded into the kernel before
142 running the ``dpdk-devbind.py`` script.
143
144 .. warning::
145
146     Due to the way VFIO works, there are certain limitations to which devices can be used with VFIO.
147     Mainly it comes down to how IOMMU groups work.
148     Any Virtual Function device can be used with VFIO on its own, but physical devices will require either all ports bound to VFIO,
149     or some of them bound to VFIO while others not being bound to anything at all.
150
151     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.
152     Therefore, the bridge driver should also be unbound from the bridge PCI device for VFIO to work with devices behind the bridge.
153
154 .. warning::
155
156     While any user can run the dpdk-devbind.py script to view the status of the network ports,
157     binding or unbinding network ports requires root privileges.
158
159 To see the status of all network ports on the system:
160
161 .. code-block:: console
162
163     ./usertools/dpdk-devbind.py --status
164
165     Network devices using DPDK-compatible driver
166     ============================================
167     0000:82:00.0 '82599EB 10-GbE NIC' drv=uio_pci_generic unused=ixgbe
168     0000:82:00.1 '82599EB 10-GbE NIC' drv=uio_pci_generic unused=ixgbe
169
170     Network devices using kernel driver
171     ===================================
172     0000:04:00.0 'I350 1-GbE NIC' if=em0  drv=igb unused=uio_pci_generic *Active*
173     0000:04:00.1 'I350 1-GbE NIC' if=eth1 drv=igb unused=uio_pci_generic
174     0000:04:00.2 'I350 1-GbE NIC' if=eth2 drv=igb unused=uio_pci_generic
175     0000:04:00.3 'I350 1-GbE NIC' if=eth3 drv=igb unused=uio_pci_generic
176
177     Other network devices
178     =====================
179     <none>
180
181 To bind device ``eth1``,``04:00.1``, to the ``uio_pci_generic`` driver:
182
183 .. code-block:: console
184
185     ./usertools/dpdk-devbind.py --bind=uio_pci_generic 04:00.1
186
187 or, alternatively,
188
189 .. code-block:: console
190
191     ./usertools/dpdk-devbind.py --bind=uio_pci_generic eth1
192
193 To restore device ``82:00.0`` to its original kernel binding:
194
195 .. code-block:: console
196
197     ./usertools/dpdk-devbind.py --bind=ixgbe 82:00.0