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