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