From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id E1F373237 for ; Thu, 30 Nov 2017 10:47:23 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Nov 2017 01:47:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,341,1508828400"; d="scan'208";a="1250236733" Received: from unknown (HELO dpdk5.bj.intel.com) ([172.16.182.182]) by fmsmga002.fm.intel.com with ESMTP; 30 Nov 2017 01:47:20 -0800 From: Zhiyong Yang To: dev@dpdk.org, yliu@fridaylinux.org, maxime.coquelin@redhat.com Cc: wei.w.wang@intel.com, jianfeng.tan@intel.com, Zhiyong Yang Date: Thu, 30 Nov 2017 17:46:48 +0800 Message-Id: <20171130094657.11470-3-zhiyong.yang@intel.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20171130094657.11470-1-zhiyong.yang@intel.com> References: <20171130094657.11470-1-zhiyong.yang@intel.com> Subject: [dpdk-dev] [PATCH 02/11] net/vhostpci: public header files X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Nov 2017 09:47:25 -0000 add public/exported files for vhostpci PMD. The structures and constants that define the method of operation of the device can be visible by both the PMD and the DPDK application. Signed-off-by: Zhiyong Yang --- drivers/net/vhostpci/vhostpci_ethdev.h | 176 ++++++++++++++++++++++++ drivers/net/vhostpci/vhostpci_net.h | 74 ++++++++++ drivers/net/vhostpci/vhostpci_pci.h | 240 +++++++++++++++++++++++++++++++++ 3 files changed, 490 insertions(+) create mode 100644 drivers/net/vhostpci/vhostpci_ethdev.h create mode 100644 drivers/net/vhostpci/vhostpci_net.h create mode 100644 drivers/net/vhostpci/vhostpci_pci.h diff --git a/drivers/net/vhostpci/vhostpci_ethdev.h b/drivers/net/vhostpci/vhostpci_ethdev.h new file mode 100644 index 000000000..3ff67dbc6 --- /dev/null +++ b/drivers/net/vhostpci/vhostpci_ethdev.h @@ -0,0 +1,176 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _VHOSTPCI_ETHDEV_H_ +#define _VHOSTPCI_ETHDEV_H_ + +#include + +#include "vhostpci_pci.h" +#include "vhostpci_net.h" + +#define VHOSTPCI_MAX_RX_QUEUES 128U +#define VHOSTPCI_MAX_TX_QUEUES 128U +#define VHOSTPCI_MAX_MAC_ADDRS 1 +#define VHOSTPCI_MIN_RX_BUFSIZE 64 +#define VHOSTPCI_MAX_RX_PKTLEN 9728U +#define VHOSTPCI_NUM_DESCRIPTORS 256U +#define VHOSTPCI_MAX_QUEUE_PAIRS 0x1 + +/* Features supported by vhostpci PMD by default. */ +#define VHOSTPCI_PMD_DEFAULT_GUEST_FEATURES \ + (1ULL << VIRTIO_NET_F_MRG_RXBUF | \ + 1ULL << VIRTIO_F_VERSION_1) + +/** + * This is the first element of the scatter-gather list. If you don't + * specify GSO or CSUM features, you can simply ignore the header. + */ +struct virtio_net_hdr { +#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /**< Use csum_start,csum_offset*/ +#define VIRTIO_NET_HDR_F_DATA_VALID 2 /**< Checksum is valid */ + uint8_t flags; +#define VIRTIO_NET_HDR_GSO_NONE 0 /**< Not a GSO frame */ +#define VIRTIO_NET_HDR_GSO_TCPV4 1 /**< GSO frame, IPv4 TCP (TSO) */ +#define VIRTIO_NET_HDR_GSO_UDP 3 /**< GSO frame, IPv4 UDP (UFO) */ +#define VIRTIO_NET_HDR_GSO_TCPV6 4 /**< GSO frame, IPv6 TCP */ +#define VIRTIO_NET_HDR_GSO_ECN 0x80 /**< TCP has ECN set */ + uint8_t gso_type; + uint16_t hdr_len; /**< Ethernet + IP + tcp/udp hdrs */ + uint16_t gso_size; /**< Bytes to append to hdr_len per frame */ + uint16_t csum_start; /**< Position to start checksumming from */ + uint16_t csum_offset; /**< Offset after that to place checksum */ +}; + +/** + * This is the version of the header to use when the MRG_RXBUF + * feature has been negotiated. + */ +struct virtio_net_hdr_mrg_rxbuf { + struct virtio_net_hdr hdr; + uint16_t num_buffers; /**< Number of merged rx buffers */ +}; + +enum {VTNET_RXQ = 0, VTNET_TXQ, VTNET_QNUM}; + +struct vhostpci_stats { + uint64_t pkts; + uint64_t bytes; + uint64_t missed_pkts; +}; + +struct vhostpci_queue { + rte_atomic32_t allow_queuing; + rte_atomic32_t while_queuing; + struct rte_mempool *mb_pool; + uint16_t port_id; + uint16_t virtqueue_id; + struct vhostpci_stats stats; + void *vpnet; +}; + +/** + * Information relating to memory regions including offsets to + * addresses in QEMUs memory file. + */ +struct vhostpci_mem_region { + uint64_t guest_phys_addr; + uint64_t guest_user_addr; + uint64_t host_user_addr; + uint64_t size; + void *mmap_addr; + uint64_t mmap_size; + uint64_t offset; + uint64_t start; + uint64_t end; +}; + +/** + * Memory structure includes region and mapping information. + */ + +struct vhostpci_memory { + uint32_t nregions; + struct vhostpci_mem_region regions[MAX_REMOTE_REGION]; +}; + +/** + * Structure contains the info for each batched memory copy. + */ +struct batch_copy_elem { + void *dst; + void *src; + uint32_t len; +}; + +/** + * Structure contains buffer address, length and descriptor index + * from vring to do scatter RX. + */ +struct buf_vector { + uint64_t buf_addr; + uint32_t buf_len; + uint32_t desc_idx; +}; + +/** + * Structure contains variables relevant to RX/TX virtqueues. + */ +struct vhostpci_virtqueue { + struct vring_desc *desc; + struct vring_avail *avail; + struct vring_used *used; + uint32_t size; + uint16_t last_avail_idx; + uint16_t last_used_idx; + int enabled; + struct vring_used_elem *shadow_used_ring; + uint16_t shadow_used_idx; + struct batch_copy_elem *batch_copy_elems; + uint16_t batch_copy_nb_elems; +} __rte_cache_aligned; + +struct vhostpci_net { + uint64_t features; + uint64_t protocol_features; + uint64_t mem_base; + uint32_t flags; + uint32_t nr_vring; + struct vhostpci_memory mem; + struct vhostpci_virtqueue *virtqueue[VHOSTPCI_MAX_QUEUE_PAIRS * 2]; + uint16_t vhost_hlen; +}; + +extern struct vhostpci_hw_internal vhostpci_hw_internal[RTE_MAX_ETHPORTS]; + +#endif /* _VHOSTPCI_ETHDEV_H_ */ diff --git a/drivers/net/vhostpci/vhostpci_net.h b/drivers/net/vhostpci/vhostpci_net.h new file mode 100644 index 000000000..0e6eef695 --- /dev/null +++ b/drivers/net/vhostpci/vhostpci_net.h @@ -0,0 +1,74 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _VHOSTPCI_NET_H_ +#define _VHOSTPCI_NET_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define VIRTIO_ID_VHOST_PCI_NET 21 /* vhost-pci-net */ + +#define REMOTE_MEM_BAR_ID 2 +#define METADATA_SIZE 4096 +#define REMOTE_MEM_BAR_SIZE 0x1000000000 + +#define MAX_REMOTE_REGION 8 + +struct vpnet_remote_mem { + uint64_t gpa; + uint64_t size; +}; + +struct vpnet_remote_vq { + uint16_t last_avail_idx; + int32_t vring_enabled; + uint32_t vring_num; + uint64_t desc_gpa; + uint64_t avail_gpa; + uint64_t used_gpa; +}; + +struct vpnet_metadata { + uint32_t nregions; + uint32_t nvqs; + struct vpnet_remote_mem mem[MAX_REMOTE_REGION]; + struct vpnet_remote_vq vq[0]; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _VHOSTPCI_NET_H_ */ diff --git a/drivers/net/vhostpci/vhostpci_pci.h b/drivers/net/vhostpci/vhostpci_pci.h new file mode 100644 index 000000000..18ec72287 --- /dev/null +++ b/drivers/net/vhostpci/vhostpci_pci.h @@ -0,0 +1,240 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _VHOSTPCI_PCI_H_ +#define _VHOSTPCI_PCI_H_ + +#include + +#include +#include +#include + +struct virtqueue; + +/* VHOSTPCI vendor/device ID. */ +#define VHOST_PCI_VENDORID 0x1AF4 +#define VHOST_PCI_NET_MODERN_DEVICEID 0x1055 + +/** + * VirtIO Header, located in BAR 0. + */ +#define VIRTIO_PCI_HOST_FEATURES 0 /* host's supported features (32bit, RO)*/ +#define VIRTIO_PCI_GUEST_FEATURES 4 /* guest's supported features (32, RW) */ +#define VIRTIO_PCI_QUEUE_PFN 8 /* physical address of VQ (32, RW) */ +#define VIRTIO_PCI_QUEUE_NUM 12 /* number of ring entries (16, RO) */ +#define VIRTIO_PCI_QUEUE_SEL 14 /* current VQ selection (16, RW) */ +#define VIRTIO_PCI_QUEUE_NOTIFY 16 /* notify host regarding VQ (16, RW) */ +#define VIRTIO_PCI_STATUS 18 /* device status register (8, RW) */ +#define VIRTIO_PCI_ISR 19 /* interrupt status register, reading + * also clears the register (8, RO) + */ + +/* The bit of the ISR which indicates a device has an interrupt. */ +#define VIRTIO_PCI_ISR_INTR 0x1 +/* The bit of the ISR which indicates a device configuration change. */ +#define VIRTIO_PCI_ISR_CONFIG 0x2 + +/* Status byte for guest to report progress. */ +#define VIRTIO_CONFIG_STATUS_RESET 0x00 +#define VIRTIO_CONFIG_STATUS_ACK 0x01 +#define VIRTIO_CONFIG_STATUS_DRIVER 0x02 +#define VIRTIO_CONFIG_STATUS_DRIVER_OK 0x04 +#define VIRTIO_CONFIG_STATUS_FEATURES_OK 0x08 +#define VIRTIO_CONFIG_STATUS_FAILED 0x80 + +/* The feature bitmap for virtio net */ +#define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ +#define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */ + +/* Can the device handle any descriptor layout? */ +#define VIRTIO_F_ANY_LAYOUT 27 + +#define VIRTIO_F_VERSION_1 32 + +#define VHOSTPCI_NET_S_LINK_UP 1 /* Link is up */ + +/** + * Maximum number of virtqueues per device. + */ +#define VHOSTPCI_MAX_VIRTQUEUE_PAIRS 8 +#define VHOSTPCI_MAX_VIRTQUEUES (VHOSTPCI_MAX_VIRTQUEUE_PAIRS * 2) + +/* Common configuration */ +#define VIRTIO_PCI_CAP_COMMON_CFG 1 +/* Notifications */ +#define VIRTIO_PCI_CAP_NOTIFY_CFG 2 +/* ISR Status */ +#define VIRTIO_PCI_CAP_ISR_CFG 3 +/* Device specific configuration */ +#define VIRTIO_PCI_CAP_DEVICE_CFG 4 +/* PCI configuration access */ +#define VIRTIO_PCI_CAP_PCI_CFG 5 + +/* This is the PCI capability header: */ +struct vpnet_pci_cap { + uint8_t cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */ + uint8_t cap_next; /* Generic PCI field: next ptr. */ + uint8_t cap_len; /* Generic PCI field: capability length */ + uint8_t cfg_type; /* Identifies the structure. */ + uint8_t bar; /* Where to find it. */ + uint8_t padding[3]; /* Pad to full dword. */ + uint32_t offset; /* Offset within bar. */ + uint32_t length; /* Length of the structure, in bytes. */ +}; + +struct vpnet_notify_cap { + struct vpnet_pci_cap cap; + uint32_t notify_off_multiplier; /* Multiplier for queue_notify_off. */ +}; + +/* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */ +struct vpnet_pci_common_cfg { + /* About the whole device. */ + uint32_t device_feature_select; /* read-write */ + uint32_t device_feature; /* read-only */ + uint32_t guest_feature_select; /* read-write */ + uint32_t guest_feature; /* read-write */ + uint16_t msix_config; /* read-write */ + uint16_t num_queues; /* read-only */ + uint8_t device_status; /* read-write */ + uint8_t config_generation; /* read-only */ + + /* About a specific virtqueue. */ + uint16_t queue_select; /* read-write */ + uint16_t queue_size; /* read-write, power of 2. */ + uint16_t queue_msix_vector; /* read-write */ + uint16_t queue_enable; /* read-write */ + uint16_t queue_notify_off; /* read-only */ + uint32_t queue_desc_lo; /* read-write */ + uint32_t queue_desc_hi; /* read-write */ + uint32_t queue_avail_lo; /* read-write */ + uint32_t queue_avail_hi; /* read-write */ + uint32_t queue_used_lo; /* read-write */ + uint32_t queue_used_hi; /* read-write */ +}; + +struct vpnet_pci_config { + /* configure mac address */ + uint8_t mac[ETHER_ADDR_LEN]; + /* link up/down status */ + uint16_t status; +} __attribute__((packed)); + +struct vhostpci_hw { + uint64_t req_guest_features; + uint64_t guest_features; + uint32_t max_queue_pairs; + uint16_t started; + uint16_t max_mtu; + uint16_t vtnet_hdr_size; + uint8_t modern; + uint16_t port_id; + uint8_t mac_addr[ETHER_ADDR_LEN]; + uint32_t notify_off_multiplier; + uint8_t *isr; + uint16_t *notify_base; + struct vpnet_pci_common_cfg *common_cfg; + struct vpnet_pci_config *dev_cfg; + struct virtqueue **vqs; + struct vhostpci_net *vpnet; +}; + +struct vpnet_pci_ops { + void (*read_dev_cfg)(struct vhostpci_hw *hw, size_t offset, + void *dst, int len); + void (*write_dev_cfg)(struct vhostpci_hw *hw, size_t offset, + const void *src, int len); + void (*reset)(struct vhostpci_hw *hw); + + uint8_t (*get_status)(struct vhostpci_hw *hw); + void (*set_status)(struct vhostpci_hw *hw, uint8_t status); + + uint64_t (*get_features)(struct vhostpci_hw *hw); + void (*set_features)(struct vhostpci_hw *hw, uint64_t features); + + uint8_t (*get_isr)(struct vhostpci_hw *hw); + + uint16_t (*set_config_irq)(struct vhostpci_hw *hw, uint16_t vec); + + uint16_t (*set_queue_irq)(struct vhostpci_hw *hw, struct virtqueue *vq, + uint16_t vec); + + uint16_t (*get_queue_num)(struct vhostpci_hw *hw, uint16_t queue_id); + + void (*notify_queue)(struct vhostpci_hw *hw, struct virtqueue *vq); +}; + +/** + * While vhostpci_hw is stored in shared memory, this structure stores + * some infos that may vary in the multiple process model locally. + * For example, the vtpci_ops pointer. + */ +struct vhostpci_hw_internal { + const struct vpnet_pci_ops *vtpci_ops; +}; + +#define VTPCI_OPS(hw) (vhostpci_hw_internal[(hw)->port_id].vtpci_ops) + +extern struct vhostpci_hw_internal vhostpci_hw_internal[RTE_MAX_ETHPORTS]; + +/* The alignment to use between consumer and producer parts of vring. */ +#define VHOST_PCI_VRING_ALIGN 4096 + +static inline int +vtpci_with_feature(struct vhostpci_hw *hw, uint64_t bit) +{ + return (hw->guest_features & (1ULL << bit)) != 0; +} + +/** + * Function declaration from vhostpci_pci.c + */ + +uint8_t vhpci_isr(struct vhostpci_hw *hw); + +uint8_t vhpci_get_status(struct vhostpci_hw *hw); + +void vhpci_init_complete(struct vhostpci_hw *hw); + +void vhpci_set_status(struct vhostpci_hw *hw, uint8_t status); + +uint64_t vhpci_negotiate_features(struct vhostpci_hw *hw, + uint64_t host_features); + +int vhostpci_pci_init(struct rte_pci_device *dev, struct vhostpci_hw *hw); + +void vhpci_read_dev_config(struct vhostpci_hw *hw, size_t offset, + void *dst, int length); + +#endif /* _VHOSTPCI_PCI_H_ */ -- 2.13.3