From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk0-f181.google.com (mail-qk0-f181.google.com [209.85.220.181]) by dpdk.org (Postfix) with ESMTP id A8FE65A54 for ; Thu, 11 Jun 2015 17:53:33 +0200 (CEST) Received: by qkhq76 with SMTP id q76so4868155qkh.2 for ; Thu, 11 Jun 2015 08:53:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0lkkiRwuWS+Sj1zFZiLTD3UCgHqIBGRku0jZJfIwkuU=; b=f1WqKXhsOKYKIejf2jcbz/dKSJJaA6DY32aVWrPVi5fvaAJiPWoT1J3XImaKv1Q5ls UWX1J7pbkHy20RQ0BY8QExQBPgUQp9A9TYjQ7aysOUPLG0RM3nioRL63DuVhRu6LLn2v rMAzi1Gc+sEo0T4DzNsTC/grrnwQnWsN0rn8qxX7LdhNSB+xoWib/DliFlgmoB5XEc2K dHNtLdq4yF/0SQEPJBV51FJCoKJv9ZUlEiWTkYqr9jvF9NJ0UplZ1FzQsRb4e15zRNWV HHmOoQLjaaCksM0YSk43EM6T3UnUw4Sxfx6pCybv973m2+PbsJDru0FMxHTtqlReIy0J XA1Q== X-Gm-Message-State: ALoCoQmLnKGZJ1wpj5UVzL5ZXa53yKG77R130oDmOTa/fKUPmci0fRx+5Fmaa1YbnDIGjQn3VTyX X-Received: by 10.55.20.12 with SMTP id e12mr20592249qkh.56.1434038013270; Thu, 11 Jun 2015 08:53:33 -0700 (PDT) Received: from urahara.home.lan (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by mx.google.com with ESMTPSA id v13sm405348qhd.31.2015.06.11.08.53.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Jun 2015 08:53:32 -0700 (PDT) From: Stephen Hemminger To: changchun.ouyang@intel.com Date: Thu, 11 Jun 2015 08:53:26 -0700 Message-Id: <1434038007-8964-5-git-send-email-stephen@networkplumber.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1434038007-8964-1-git-send-email-stephen@networkplumber.org> References: <1434038007-8964-1-git-send-email-stephen@networkplumber.org> Cc: dev@dpdk.org, Stephen Hemminger Subject: [dpdk-dev] [PATCH 4/5] virtio: clarify feature bit handling X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jun 2015 15:53:34 -0000 From: Stephen Hemminger Change the features from bit mask to bit number. This allows the DPDK driver to use the definitions from Linux (yes the header files already use a license compatiable with DPDK). This makes DPDK driver handle future feature bit changes. Get rid of double negative code in the feature bit intialization. Instead just have a new define with the list of feature bits implemented. Signed-off-by: Stephen Hemminger --- drivers/net/virtio/virtio_ethdev.c | 17 +------ drivers/net/virtio/virtio_ethdev.h | 27 ++++------- drivers/net/virtio/virtio_pci.h | 96 +++++++++++++++++++------------------- drivers/net/virtio/virtqueue.h | 8 +--- 4 files changed, 61 insertions(+), 87 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index ad49fc1..2afa371 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -799,23 +799,10 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on) static void virtio_negotiate_features(struct virtio_hw *hw) { - uint32_t host_features, mask; - - /* checksum offload not implemented */ - mask = VIRTIO_NET_F_CSUM | VIRTIO_NET_F_GUEST_CSUM; - - /* TSO and LRO are only available when their corresponding - * checksum offload feature is also negotiated. - */ - mask |= VIRTIO_NET_F_HOST_TSO4 | VIRTIO_NET_F_HOST_TSO6 | VIRTIO_NET_F_HOST_ECN; - mask |= VIRTIO_NET_F_GUEST_TSO4 | VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_ECN; - mask |= VTNET_LRO_FEATURES; - - /* not negotiating INDIRECT descriptor table support */ - mask |= VIRTIO_RING_F_INDIRECT_DESC; + uint32_t host_features; /* Prepare guest_features: feature that driver wants to support */ - hw->guest_features = VTNET_FEATURES & ~mask; + hw->guest_features = VIRTIO_PMD_GUEST_FEATURES; PMD_INIT_LOG(DEBUG, "guest_features before negotiate = %x", hw->guest_features); diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h index e6d4533..df2cb7d 100644 --- a/drivers/net/virtio/virtio_ethdev.h +++ b/drivers/net/virtio/virtio_ethdev.h @@ -56,24 +56,15 @@ #define VIRTIO_MAX_RX_PKTLEN 9728 /* Features desired/implemented by this driver. */ -#define VTNET_FEATURES \ - (VIRTIO_NET_F_MAC | \ - VIRTIO_NET_F_STATUS | \ - VIRTIO_NET_F_MQ | \ - VIRTIO_NET_F_CTRL_MAC_ADDR | \ - VIRTIO_NET_F_CTRL_VQ | \ - VIRTIO_NET_F_CTRL_RX | \ - VIRTIO_NET_F_CTRL_VLAN | \ - VIRTIO_NET_F_CSUM | \ - VIRTIO_NET_F_HOST_TSO4 | \ - VIRTIO_NET_F_HOST_TSO6 | \ - VIRTIO_NET_F_HOST_ECN | \ - VIRTIO_NET_F_GUEST_CSUM | \ - VIRTIO_NET_F_GUEST_TSO4 | \ - VIRTIO_NET_F_GUEST_TSO6 | \ - VIRTIO_NET_F_GUEST_ECN | \ - VIRTIO_NET_F_MRG_RXBUF | \ - VIRTIO_RING_F_INDIRECT_DESC) +#define VIRTIO_PMD_GUEST_FEATURES \ + (1u << VIRTIO_NET_F_MAC | \ + 1u << VIRTIO_NET_F_STATUS | \ + 1u << VIRTIO_NET_F_MQ | \ + 1u << VIRTIO_NET_F_CTRL_MAC_ADDR | \ + 1u << VIRTIO_NET_F_CTRL_VQ | \ + 1u << VIRTIO_NET_F_CTRL_RX | \ + 1u << VIRTIO_NET_F_CTRL_VLAN | \ + 1u << VIRTIO_NET_F_MRG_RXBUF) /* * CQ function prototype diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h index 64d9c34..47f722a 100644 --- a/drivers/net/virtio/virtio_pci.h +++ b/drivers/net/virtio/virtio_pci.h @@ -96,26 +96,6 @@ struct virtqueue; #define VIRTIO_CONFIG_STATUS_FAILED 0x80 /* - * Generate interrupt when the virtqueue ring is - * completely used, even if we've suppressed them. - */ -#define VIRTIO_F_NOTIFY_ON_EMPTY (1 << 24) - -/* - * The guest should never negotiate this feature; it - * is used to detect faulty drivers. - */ -#define VIRTIO_F_BAD_FEATURE (1 << 30) - -/* - * Some VirtIO feature bits (currently bits 28 through 31) are - * reserved for the transport being used (eg. virtio_ring), the - * rest are per-device feature bits. - */ -#define VIRTIO_TRANSPORT_F_START 28 -#define VIRTIO_TRANSPORT_F_END 32 - -/* * Each virtqueue indirect descriptor list must be physically contiguous. * To allow us to malloc(9) each list individually, limit the number * supported to what will fit in one page. With 4KB pages, this is a limit @@ -128,33 +108,55 @@ struct virtqueue; #define VIRTIO_MAX_INDIRECT ((int) (PAGE_SIZE / 16)) /* The feature bitmap for virtio net */ -#define VIRTIO_NET_F_CSUM 0x00001 /* Host handles pkts w/ partial csum */ -#define VIRTIO_NET_F_GUEST_CSUM 0x00002 /* Guest handles pkts w/ partial csum*/ -#define VIRTIO_NET_F_MAC 0x00020 /* Host has given MAC address. */ -#define VIRTIO_NET_F_GSO 0x00040 /* Host handles pkts w/ any GSO type */ -#define VIRTIO_NET_F_GUEST_TSO4 0x00080 /* Guest can handle TSOv4 in. */ -#define VIRTIO_NET_F_GUEST_TSO6 0x00100 /* Guest can handle TSOv6 in. */ -#define VIRTIO_NET_F_GUEST_ECN 0x00200 /* Guest can handle TSO[6] w/ ECN in.*/ -#define VIRTIO_NET_F_GUEST_UFO 0x00400 /* Guest can handle UFO in. */ -#define VIRTIO_NET_F_HOST_TSO4 0x00800 /* Host can handle TSOv4 in. */ -#define VIRTIO_NET_F_HOST_TSO6 0x01000 /* Host can handle TSOv6 in. */ -#define VIRTIO_NET_F_HOST_ECN 0x02000 /* Host can handle TSO[6] w/ ECN in. */ -#define VIRTIO_NET_F_HOST_UFO 0x04000 /* Host can handle UFO in. */ -#define VIRTIO_NET_F_MRG_RXBUF 0x08000 /* Host can merge receive buffers. */ -#define VIRTIO_NET_F_STATUS 0x10000 /* virtio_net_config.status available*/ -#define VIRTIO_NET_F_CTRL_VQ 0x20000 /* Control channel available */ -#define VIRTIO_NET_F_CTRL_RX 0x40000 /* Control channel RX mode support */ -#define VIRTIO_NET_F_CTRL_VLAN 0x80000 /* Control channel VLAN filtering */ -#define VIRTIO_NET_F_CTRL_RX_EXTRA 0x100000 /* Extra RX mode control support */ -#define VIRTIO_RING_F_INDIRECT_DESC 0x10000000 /* Support for indirect buffer descriptors. */ -/* The guest publishes the used index for which it expects an interrupt - * at the end of the avail ring. Host should ignore the avail->flags field. - * The host publishes the avail index for which it expects a kick - * at the end of the used ring. Guest should ignore the used->flags field. +#define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */ +#define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */ +#define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ +#define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */ +#define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */ +#define VIRTIO_NET_F_GUEST_ECN 9 /* Guest can handle TSO[6] w/ ECN in. */ +#define VIRTIO_NET_F_GUEST_UFO 10 /* Guest can handle UFO in. */ +#define VIRTIO_NET_F_HOST_TSO4 11 /* Host can handle TSOv4 in. */ +#define VIRTIO_NET_F_HOST_TSO6 12 /* Host can handle TSOv6 in. */ +#define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */ +#define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */ +#define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */ +#define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */ +#define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */ +#define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */ +#define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */ +#define VIRTIO_NET_F_CTRL_RX_EXTRA 20 /* Extra RX mode control support */ +#define VIRTIO_NET_F_GUEST_ANNOUNCE 21 /* Guest can announce device on the + * network */ +#define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow + * Steering */ +#define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ + +/* Do we get callbacks when the ring is completely used, even if we've + * suppressed them? */ +#define VIRTIO_F_NOTIFY_ON_EMPTY 24 + +/* Can the device handle any descriptor layout? */ +#define VIRTIO_F_ANY_LAYOUT 27 + +/* We support indirect buffer descriptors */ +#define VIRTIO_RING_F_INDIRECT_DESC 28 + +/* + * Some VirtIO feature bits (currently bits 28 through 31) are + * reserved for the transport being used (eg. virtio_ring), the + * rest are per-device feature bits. */ -#define VIRTIO_RING_F_EVENT_IDX 0x20000000 +#define VIRTIO_TRANSPORT_F_START 28 +#define VIRTIO_TRANSPORT_F_END 32 + +/* The Guest publishes the used index for which it expects an interrupt + * at the end of the avail ring. Host should ignore the avail->flags field. */ +/* The Host publishes the avail index for which it expects a kick + * at the end of the used ring. Guest should ignore the used->flags field. */ +#define VIRTIO_RING_F_EVENT_IDX 29 -#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ +#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ +#define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */ /* * Maximum number of virtqueues per device. @@ -243,9 +245,9 @@ outl_p(unsigned int data, unsigned int port) outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg)))) static inline int -vtpci_with_feature(struct virtio_hw *hw, uint32_t feature) +vtpci_with_feature(struct virtio_hw *hw, uint32_t bit) { - return (hw->guest_features & feature) != 0; + return (hw->guest_features & (1u << bit)) != 0; } /* diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h index 9d6079e..7789411 100644 --- a/drivers/net/virtio/virtqueue.h +++ b/drivers/net/virtio/virtqueue.h @@ -202,18 +202,12 @@ struct virtqueue { }; /* If multiqueue is provided by host, then we suppport it. */ -#ifndef VIRTIO_NET_F_MQ -/* Device supports Receive Flow Steering */ -#define VIRTIO_NET_F_MQ 0x400000 #define VIRTIO_NET_CTRL_MQ 4 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 -#endif -#ifndef VIRTIO_NET_F_CTRL_MAC_ADDR -#define VIRTIO_NET_F_CTRL_MAC_ADDR 0x800000 + #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1 -#endif /** * This is the first element of the scatter-gather list. If you don't -- 2.1.4