xref: /dpdk/doc/guides/prog_guide/rawdev.rst (revision a9bb0c44c775784f3d6cafd4d774301db633cb47)
1*a9bb0c44SShreyansh Jain..  SPDX-License-Identifier: BSD-3-Clause
2*a9bb0c44SShreyansh Jain    Copyright 2018 NXP
3*a9bb0c44SShreyansh Jain
4*a9bb0c44SShreyansh JainRawdevice Library
5*a9bb0c44SShreyansh Jain=================
6*a9bb0c44SShreyansh Jain
7*a9bb0c44SShreyansh JainIntroduction
8*a9bb0c44SShreyansh Jain------------
9*a9bb0c44SShreyansh Jain
10*a9bb0c44SShreyansh JainIn terms of device flavor (type) support, DPDK currently has ethernet
11*a9bb0c44SShreyansh Jain(lib_ether), cryptodev (libcryptodev), eventdev (libeventdev) and vdev
12*a9bb0c44SShreyansh Jain(virtual device) support.
13*a9bb0c44SShreyansh Jain
14*a9bb0c44SShreyansh JainFor a new type of device, for example an accelerator, there are not many
15*a9bb0c44SShreyansh Jainoptions except:
16*a9bb0c44SShreyansh Jain1. create another lib/librte_MySpecialDev, driver/MySpecialDrv and use it
17*a9bb0c44SShreyansh Jainthrough Bus/PMD model.
18*a9bb0c44SShreyansh Jain2. Or, create a vdev and implement necessary custom APIs which are directly
19*a9bb0c44SShreyansh Jainexposed from driver layer. However this may still require changes in bus code
20*a9bb0c44SShreyansh Jainin DPDK.
21*a9bb0c44SShreyansh Jain
22*a9bb0c44SShreyansh JainThe DPDK Rawdev library is an abstraction that provides the DPDK framework a
23*a9bb0c44SShreyansh Jainway to manage such devices in a generic manner without expecting changes to
24*a9bb0c44SShreyansh Jainlibrary or EAL for each device type. This library provides a generic set of
25*a9bb0c44SShreyansh Jainoperations and APIs for framework and Applications to use, respectively, for
26*a9bb0c44SShreyansh Jaininterfacing with such type of devices.
27*a9bb0c44SShreyansh Jain
28*a9bb0c44SShreyansh JainDesign
29*a9bb0c44SShreyansh Jain------
30*a9bb0c44SShreyansh Jain
31*a9bb0c44SShreyansh JainKey factors guiding design of the Rawdevice library:
32*a9bb0c44SShreyansh Jain
33*a9bb0c44SShreyansh Jain1. Following are some generic operations which can be treated as applicable
34*a9bb0c44SShreyansh Jain   to a large subset of device types. None of the operations are mandatory to
35*a9bb0c44SShreyansh Jain   be implemented by a driver. Application should also be design for proper
36*a9bb0c44SShreyansh Jain   handling for unsupported APIs.
37*a9bb0c44SShreyansh Jain
38*a9bb0c44SShreyansh Jain  * Device Start/Stop - In some cases, 'reset' might also be required which
39*a9bb0c44SShreyansh Jain    has different semantics than a start-stop-start cycle.
40*a9bb0c44SShreyansh Jain  * Configuration - Device, Queue or any other sub-system configuration
41*a9bb0c44SShreyansh Jain  * I/O - Sending a series of buffers which can enclose any arbitrary data
42*a9bb0c44SShreyansh Jain  * Statistics - Fetch arbitrary device statistics
43*a9bb0c44SShreyansh Jain  * Firmware Management - Firmware load/unload/status
44*a9bb0c44SShreyansh Jain
45*a9bb0c44SShreyansh Jain2. Application API should be able to pass along arbitrary state information
46*a9bb0c44SShreyansh Jain   to/fro device driver. This can be achieved by maintaining context
47*a9bb0c44SShreyansh Jain   information through opaque data or pointers.
48*a9bb0c44SShreyansh Jain
49*a9bb0c44SShreyansh JainFigure below outlines the layout of the rawdevice library and device vis-a-vis
50*a9bb0c44SShreyansh Jainother well known device types like eth and crypto:
51*a9bb0c44SShreyansh Jain
52*a9bb0c44SShreyansh Jain.. code-block:: console
53*a9bb0c44SShreyansh Jain
54*a9bb0c44SShreyansh Jain     +-----------------------------------------------------------+
55*a9bb0c44SShreyansh Jain     |                        Application(s)                     |
56*a9bb0c44SShreyansh Jain     +------------------------------.----------------------------+
57*a9bb0c44SShreyansh Jain                                    |
58*a9bb0c44SShreyansh Jain                                    |
59*a9bb0c44SShreyansh Jain     +------------------------------'----------------------------+
60*a9bb0c44SShreyansh Jain     |                     DPDK Framework (APIs)                 |
61*a9bb0c44SShreyansh Jain     +--------------|----|-----------------|---------------------+
62*a9bb0c44SShreyansh Jain                   /      \                 \
63*a9bb0c44SShreyansh Jain            (crypto ops)  (eth ops)      (rawdev ops)        +----+
64*a9bb0c44SShreyansh Jain            /               \                 \              |DrvA|
65*a9bb0c44SShreyansh Jain     +-----'---+        +----`----+        +---'-----+       +----+
66*a9bb0c44SShreyansh Jain     | crypto  |        | ethdev  |        | raw     |
67*a9bb0c44SShreyansh Jain     +--/------+        +---/-----+        +----/----+       +----+
68*a9bb0c44SShreyansh Jain       /\                __/\                  /   ..........|DrvB|
69*a9bb0c44SShreyansh Jain      /  \              /    \                / ../    \     +----+
70*a9bb0c44SShreyansh Jain  +====+ +====+    +====+ +====+            +==/=+      ```Bus Probe
71*a9bb0c44SShreyansh Jain  |DevA| |DevB|    |DevC| |DevD|            |DevF|
72*a9bb0c44SShreyansh Jain  +====+ +====+    +====+ +====+            +====+
73*a9bb0c44SShreyansh Jain    |      |        |      |                 |
74*a9bb0c44SShreyansh Jain  ``|``````|````````|``````|`````````````````|````````Bus Scan
75*a9bb0c44SShreyansh Jain   (PCI)   |       (PCI)  (PCI)            (PCI)
76*a9bb0c44SShreyansh Jain         (BusA)
77*a9bb0c44SShreyansh Jain
78*a9bb0c44SShreyansh Jain * It is assumed above that DrvB is a PCI type driver which registers itself
79*a9bb0c44SShreyansh Jain   with PCI Bus
80*a9bb0c44SShreyansh Jain * Thereafter, when the PCI scan is done, during probe DrvB would match the
81*a9bb0c44SShreyansh Jain   rawdev DevF ID and take control of device
82*a9bb0c44SShreyansh Jain * Applications can then continue using the device through rawdev API
83*a9bb0c44SShreyansh Jain   interfaces
84*a9bb0c44SShreyansh Jain
85*a9bb0c44SShreyansh Jain
86*a9bb0c44SShreyansh JainDevice Identification
87*a9bb0c44SShreyansh Jain~~~~~~~~~~~~~~~~~~~~~
88*a9bb0c44SShreyansh Jain
89*a9bb0c44SShreyansh JainPhysical rawdev devices are discovered during the Bus scan executed at DPDK
90*a9bb0c44SShreyansh Jaininitialization, based on their identification and probing with corresponding
91*a9bb0c44SShreyansh Jaindriver. Thus, a generic device needs to have an identifier and a driver
92*a9bb0c44SShreyansh Jaincapable of identifying it through this identifier.
93*a9bb0c44SShreyansh Jain
94*a9bb0c44SShreyansh JainVirtual devices can be created by two mechanisms, either using the EAL command
95*a9bb0c44SShreyansh Jainline options or from within the application using an EAL API directly.
96*a9bb0c44SShreyansh Jain
97*a9bb0c44SShreyansh JainFrom the command line using the --vdev EAL option
98*a9bb0c44SShreyansh Jain
99*a9bb0c44SShreyansh Jain.. code-block:: console
100*a9bb0c44SShreyansh Jain
101*a9bb0c44SShreyansh Jain   --vdev 'rawdev_dev1'
102*a9bb0c44SShreyansh Jain
103*a9bb0c44SShreyansh JainOur using the rte_vdev_init API within the application code.
104*a9bb0c44SShreyansh Jain
105*a9bb0c44SShreyansh Jain.. code-block:: c
106*a9bb0c44SShreyansh Jain
107*a9bb0c44SShreyansh Jain    rte_vdev_init("rawdev_dev1", NULL)
108