dpdk/drivers/net/avp/rte_avp_common.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: (BSD-3-Clause OR LGPL-2.1)
   2 * Copyright(c) 2010-2013 Intel Corporation.
   3 * Copyright(c) 2014-2017 Wind River Systems, Inc.
   4 */
   5
   6#ifndef _RTE_AVP_COMMON_H_
   7#define _RTE_AVP_COMMON_H_
   8
   9#ifdef __KERNEL__
  10#include <linux/if.h>
  11#define RTE_STD_C11
  12#else
  13#include <stdint.h>
  14#include <rte_common.h>
  15#include <rte_config.h>
  16#include <rte_memory.h>
  17#include <rte_ether.h>
  18#include <rte_atomic.h>
  19#endif
  20
  21#ifdef __cplusplus
  22extern "C" {
  23#endif
  24
  25/**
  26 * AVP name is part of network device name.
  27 */
  28#define RTE_AVP_NAMESIZE 32
  29
  30/**
  31 * AVP alias is a user-defined value used for lookups from secondary
  32 * processes.  Typically, this is a UUID.
  33 */
  34#define RTE_AVP_ALIASSIZE 128
  35
  36/*
  37 * Request id.
  38 */
  39enum rte_avp_req_id {
  40        RTE_AVP_REQ_UNKNOWN = 0,
  41        RTE_AVP_REQ_CHANGE_MTU,
  42        RTE_AVP_REQ_CFG_NETWORK_IF,
  43        RTE_AVP_REQ_CFG_DEVICE,
  44        RTE_AVP_REQ_SHUTDOWN_DEVICE,
  45        RTE_AVP_REQ_MAX,
  46};
  47
  48/**@{ AVP device driver types */
  49#define RTE_AVP_DRIVER_TYPE_UNKNOWN 0
  50#define RTE_AVP_DRIVER_TYPE_DPDK 1
  51#define RTE_AVP_DRIVER_TYPE_KERNEL 2
  52#define RTE_AVP_DRIVER_TYPE_QEMU 3
  53/**@} */
  54
  55/**@{ AVP device operational modes */
  56#define RTE_AVP_MODE_HOST 0 /**< AVP interface created in host */
  57#define RTE_AVP_MODE_GUEST 1 /**< AVP interface created for export to guest */
  58#define RTE_AVP_MODE_TRACE 2 /**< AVP interface created for packet tracing */
  59/**@} */
  60
  61/*
  62 * Structure for AVP queue configuration query request/result
  63 */
  64struct rte_avp_device_config {
  65        uint64_t device_id;     /**< Unique system identifier */
  66        uint32_t driver_type; /**< Device Driver type */
  67        uint32_t driver_version; /**< Device Driver version */
  68        uint32_t features; /**< Negotiated features */
  69        uint16_t num_tx_queues; /**< Number of active transmit queues */
  70        uint16_t num_rx_queues; /**< Number of active receive queues */
  71        uint8_t if_up; /**< 1: interface up, 0: interface down */
  72} __rte_packed;
  73
  74/*
  75 * Structure for AVP request.
  76 */
  77struct rte_avp_request {
  78        uint32_t req_id; /**< Request id */
  79        RTE_STD_C11
  80        union {
  81                uint32_t new_mtu; /**< New MTU */
  82                uint8_t if_up;  /**< 1: interface up, 0: interface down */
  83        struct rte_avp_device_config config; /**< Queue configuration */
  84        };
  85        int32_t result; /**< Result for processing request */
  86} __rte_packed;
  87
  88/*
  89 * FIFO struct mapped in a shared memory. It describes a circular buffer FIFO
  90 * Write and read should wrap around. FIFO is empty when write == read
  91 * Writing should never overwrite the read position
  92 */
  93struct rte_avp_fifo {
  94        volatile unsigned int write; /**< Next position to be written*/
  95        volatile unsigned int read; /**< Next position to be read */
  96        unsigned int len; /**< Circular buffer length */
  97        unsigned int elem_size; /**< Pointer size - for 32/64 bit OS */
  98        void *volatile buffer[]; /**< The buffer contains mbuf pointers */
  99};
 100
 101
 102/*
 103 * AVP packet buffer header used to define the exchange of packet data.
 104 */
 105struct rte_avp_desc {
 106        uint64_t pad0;
 107        void *pkt_mbuf; /**< Reference to packet mbuf */
 108        uint8_t pad1[14];
 109        uint16_t ol_flags; /**< Offload features. */
 110        void *next;     /**< Reference to next buffer in chain */
 111        void *data;     /**< Start address of data in segment buffer. */
 112        uint16_t data_len; /**< Amount of data in segment buffer. */
 113        uint8_t nb_segs; /**< Number of segments */
 114        uint8_t pad2;
 115        uint16_t pkt_len; /**< Total pkt len: sum of all segment data_len. */
 116        uint32_t pad3;
 117        uint16_t vlan_tci; /**< VLAN Tag Control Identifier (CPU order). */
 118        uint32_t pad4;
 119} __rte_packed __rte_cache_aligned;
 120
 121
 122/**{ AVP device features */
 123#define RTE_AVP_FEATURE_VLAN_OFFLOAD (1 << 0) /**< Emulated HW VLAN offload */
 124/**@} */
 125
 126
 127/**@{ Offload feature flags */
 128#define RTE_AVP_TX_VLAN_PKT 0x0001 /**< TX packet is a 802.1q VLAN packet. */
 129#define RTE_AVP_RX_VLAN_PKT 0x0800 /**< RX packet is a 802.1q VLAN packet. */
 130/**@} */
 131
 132
 133/**@{ AVP PCI identifiers */
 134#define RTE_AVP_PCI_VENDOR_ID   0x1af4
 135#define RTE_AVP_PCI_DEVICE_ID   0x1110
 136/**@} */
 137
 138/**@{ AVP PCI subsystem identifiers */
 139#define RTE_AVP_PCI_SUB_VENDOR_ID RTE_AVP_PCI_VENDOR_ID
 140#define RTE_AVP_PCI_SUB_DEVICE_ID 0x1104
 141/**@} */
 142
 143/**@{ AVP PCI BAR definitions */
 144#define RTE_AVP_PCI_MMIO_BAR   0
 145#define RTE_AVP_PCI_MSIX_BAR   1
 146#define RTE_AVP_PCI_MEMORY_BAR 2
 147#define RTE_AVP_PCI_MEMMAP_BAR 4
 148#define RTE_AVP_PCI_DEVICE_BAR 5
 149#define RTE_AVP_PCI_MAX_BAR    6
 150/**@} */
 151
 152/**@{ AVP PCI BAR name definitions */
 153#define RTE_AVP_MMIO_BAR_NAME   "avp-mmio"
 154#define RTE_AVP_MSIX_BAR_NAME   "avp-msix"
 155#define RTE_AVP_MEMORY_BAR_NAME "avp-memory"
 156#define RTE_AVP_MEMMAP_BAR_NAME "avp-memmap"
 157#define RTE_AVP_DEVICE_BAR_NAME "avp-device"
 158/**@} */
 159
 160/**@{ AVP PCI MSI-X vectors */
 161#define RTE_AVP_MIGRATION_MSIX_VECTOR 0 /**< Migration interrupts */
 162#define RTE_AVP_MAX_MSIX_VECTORS 1
 163/**@} */
 164
 165/**@} AVP Migration status/ack register values */
 166#define RTE_AVP_MIGRATION_NONE      0 /**< Migration never executed */
 167#define RTE_AVP_MIGRATION_DETACHED  1 /**< Device attached during migration */
 168#define RTE_AVP_MIGRATION_ATTACHED  2 /**< Device reattached during migration */
 169#define RTE_AVP_MIGRATION_ERROR     3 /**< Device failed to attach/detach */
 170/**@} */
 171
 172/**@} AVP MMIO Register Offsets */
 173#define RTE_AVP_REGISTER_BASE 0
 174#define RTE_AVP_INTERRUPT_MASK_OFFSET (RTE_AVP_REGISTER_BASE + 0)
 175#define RTE_AVP_INTERRUPT_STATUS_OFFSET (RTE_AVP_REGISTER_BASE + 4)
 176#define RTE_AVP_MIGRATION_STATUS_OFFSET (RTE_AVP_REGISTER_BASE + 8)
 177#define RTE_AVP_MIGRATION_ACK_OFFSET (RTE_AVP_REGISTER_BASE + 12)
 178/**@} */
 179
 180/**@} AVP Interrupt Status Mask */
 181#define RTE_AVP_MIGRATION_INTERRUPT_MASK (1 << 1)
 182#define RTE_AVP_APP_INTERRUPTS_MASK      0xFFFFFFFF
 183#define RTE_AVP_NO_INTERRUPTS_MASK       0
 184/**@} */
 185
 186/*
 187 * Maximum number of memory regions to export
 188 */
 189#define RTE_AVP_MAX_MAPS  2048
 190
 191/*
 192 * Description of a single memory region
 193 */
 194struct rte_avp_memmap {
 195        void *addr;
 196        rte_iova_t phys_addr;
 197        uint64_t length;
 198};
 199
 200/*
 201 * AVP memory mapping validation marker
 202 */
 203#define RTE_AVP_MEMMAP_MAGIC 0x20131969
 204
 205/**@{  AVP memory map versions */
 206#define RTE_AVP_MEMMAP_VERSION_1 1
 207#define RTE_AVP_MEMMAP_VERSION RTE_AVP_MEMMAP_VERSION_1
 208/**@} */
 209
 210/*
 211 * Defines a list of memory regions exported from the host to the guest
 212 */
 213struct rte_avp_memmap_info {
 214        uint32_t magic; /**< Memory validation marker */
 215        uint32_t version; /**< Data format version */
 216        uint32_t nb_maps;
 217        struct rte_avp_memmap maps[RTE_AVP_MAX_MAPS];
 218};
 219
 220/*
 221 * AVP device memory validation marker
 222 */
 223#define RTE_AVP_DEVICE_MAGIC 0x20131975
 224
 225/**@{  AVP device map versions
 226 * WARNING:  do not change the format or names of these variables.  They are
 227 * automatically parsed from the build system to generate the SDK package
 228 * name.
 229 **/
 230#define RTE_AVP_RELEASE_VERSION_1 1
 231#define RTE_AVP_RELEASE_VERSION RTE_AVP_RELEASE_VERSION_1
 232#define RTE_AVP_MAJOR_VERSION_0 0
 233#define RTE_AVP_MAJOR_VERSION_1 1
 234#define RTE_AVP_MAJOR_VERSION_2 2
 235#define RTE_AVP_MAJOR_VERSION RTE_AVP_MAJOR_VERSION_2
 236#define RTE_AVP_MINOR_VERSION_0 0
 237#define RTE_AVP_MINOR_VERSION_1 1
 238#define RTE_AVP_MINOR_VERSION_13 13
 239#define RTE_AVP_MINOR_VERSION RTE_AVP_MINOR_VERSION_13
 240/**@} */
 241
 242
 243/**
 244 * Generates a 32-bit version number from the specified version number
 245 * components
 246 */
 247#define RTE_AVP_MAKE_VERSION(_release, _major, _minor) \
 248((((_release) & 0xffff) << 16) | (((_major) & 0xff) << 8) | ((_minor) & 0xff))
 249
 250
 251/**
 252 * Represents the current version of the AVP host driver
 253 * WARNING:  in the current development branch the host and guest driver
 254 * version should always be the same.  When patching guest features back to
 255 * GA releases the host version number should not be updated unless there was
 256 * an actual change made to the host driver.
 257 */
 258#define RTE_AVP_CURRENT_HOST_VERSION \
 259RTE_AVP_MAKE_VERSION(RTE_AVP_RELEASE_VERSION_1, \
 260                     RTE_AVP_MAJOR_VERSION_0, \
 261                     RTE_AVP_MINOR_VERSION_1)
 262
 263
 264/**
 265 * Represents the current version of the AVP guest drivers
 266 */
 267#define RTE_AVP_CURRENT_GUEST_VERSION \
 268RTE_AVP_MAKE_VERSION(RTE_AVP_RELEASE_VERSION_1, \
 269                     RTE_AVP_MAJOR_VERSION_2, \
 270                     RTE_AVP_MINOR_VERSION_13)
 271
 272/**
 273 * Access AVP device version values
 274 */
 275#define RTE_AVP_GET_RELEASE_VERSION(_version) (((_version) >> 16) & 0xffff)
 276#define RTE_AVP_GET_MAJOR_VERSION(_version) (((_version) >> 8) & 0xff)
 277#define RTE_AVP_GET_MINOR_VERSION(_version) ((_version) & 0xff)
 278/**@}*/
 279
 280
 281/**
 282 * Remove the minor version number so that only the release and major versions
 283 * are used for comparisons.
 284 */
 285#define RTE_AVP_STRIP_MINOR_VERSION(_version) ((_version) >> 8)
 286
 287
 288/**
 289 * Defines the number of mbuf pools supported per device (1 per socket)
 290 */
 291#define RTE_AVP_MAX_MEMPOOLS 8
 292
 293/*
 294 * Defines address translation parameters for each support mbuf pool
 295 */
 296struct rte_avp_mempool_info {
 297        void *addr;
 298        rte_iova_t phys_addr;
 299        uint64_t length;
 300};
 301
 302/*
 303 * Struct used to create a AVP device. Passed to the kernel in IOCTL call or
 304 * via inter-VM shared memory when used in a guest.
 305 */
 306struct rte_avp_device_info {
 307        uint32_t magic; /**< Memory validation marker */
 308        uint32_t version; /**< Data format version */
 309
 310        char ifname[RTE_AVP_NAMESIZE];  /**< Network device name for AVP */
 311
 312        rte_iova_t tx_phys;
 313        rte_iova_t rx_phys;
 314        rte_iova_t alloc_phys;
 315        rte_iova_t free_phys;
 316
 317        uint32_t features; /**< Supported feature bitmap */
 318        uint8_t min_rx_queues; /**< Minimum supported receive/free queues */
 319        uint8_t num_rx_queues; /**< Recommended number of receive/free queues */
 320        uint8_t max_rx_queues; /**< Maximum supported receive/free queues */
 321        uint8_t min_tx_queues; /**< Minimum supported transmit/alloc queues */
 322        uint8_t num_tx_queues;
 323        /**< Recommended number of transmit/alloc queues */
 324        uint8_t max_tx_queues; /**< Maximum supported transmit/alloc queues */
 325
 326        uint32_t tx_size; /**< Size of each transmit queue */
 327        uint32_t rx_size; /**< Size of each receive queue */
 328        uint32_t alloc_size; /**< Size of each alloc queue */
 329        uint32_t free_size;     /**< Size of each free queue */
 330
 331        /* Used by Ethtool */
 332        rte_iova_t req_phys;
 333        rte_iova_t resp_phys;
 334        rte_iova_t sync_phys;
 335        void *sync_va;
 336
 337        /* mbuf mempool (used when a single memory area is supported) */
 338        void *mbuf_va;
 339        rte_iova_t mbuf_phys;
 340
 341        /* mbuf mempools */
 342        struct rte_avp_mempool_info pool[RTE_AVP_MAX_MEMPOOLS];
 343
 344#ifdef __KERNEL__
 345        /* Ethernet info */
 346        char ethaddr[ETH_ALEN];
 347#else
 348        char ethaddr[RTE_ETHER_ADDR_LEN];
 349#endif
 350
 351        uint8_t mode; /**< device mode, i.e guest, host, trace */
 352
 353        /* mbuf size */
 354        unsigned int mbuf_size;
 355
 356        /*
 357         * unique id to differentiate between two instantiations of the same
 358         * AVP device (i.e., the guest needs to know if the device has been
 359         * deleted and recreated).
 360         */
 361        uint64_t device_id;
 362
 363        uint32_t max_rx_pkt_len; /**< Maximum receive unit size */
 364};
 365
 366#define RTE_AVP_MAX_QUEUES 8 /**< Maximum number of queues per device */
 367
 368/** Maximum number of chained mbufs in a packet */
 369#define RTE_AVP_MAX_MBUF_SEGMENTS 5
 370
 371#define RTE_AVP_DEVICE "avp"
 372
 373#define RTE_AVP_IOCTL_TEST    _IOWR(0, 1, int)
 374#define RTE_AVP_IOCTL_CREATE  _IOWR(0, 2, struct rte_avp_device_info)
 375#define RTE_AVP_IOCTL_RELEASE _IOWR(0, 3, struct rte_avp_device_info)
 376#define RTE_AVP_IOCTL_QUERY   _IOWR(0, 4, struct rte_avp_device_config)
 377
 378#ifdef __cplusplus
 379}
 380#endif
 381
 382#endif /* _RTE_AVP_COMMON_H_ */
 383