From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1DC5146138; Mon, 27 Jan 2025 08:41:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CC8F54064E; Mon, 27 Jan 2025 08:41:57 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 637334060B for ; Mon, 27 Jan 2025 08:41:56 +0100 (CET) Received: from pps.filterd (m0431383.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50R6VEok006851; Sun, 26 Jan 2025 23:41:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=F 0i+TU8g+fmV7BcjJf3KYxOjmKjNcsJotU9WMUu+X2s=; b=LQR0Dp2Ul61mn8mNj 5t+oiWnH6vcJ71t7+oHIDd4ibSeasMVH5zQnpi2ynJJ9ouBmQoslZb7jG/7ft9D6 8PVNLb4whnwUjCIHi1srKkX2YcD1p/uzrVE5l7OB2+HFMpF3BNO4z3e9VBK4pwjD 2bZ830eD+a+sq96h/FNcewSFieXuQSCBFzZMVyVI8wk23EPUljm+/ETc1J4xzYeg aSuSATKnl0XjpKDuLnbCGNkmhrbDvz87iIlL8IQsSZHvPE90x1QHG/O8qqcZ+wjI vj7cQY4mqgLlgFQ60KUOImoDZI17rDu2JRQwmmzZVprzYah82yH/ahoM6q+7F4+p 6y3pg== Received: from dc6wp-exch02.marvell.com ([4.21.29.225]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 44e4x3r2r4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 26 Jan 2025 23:41:55 -0800 (PST) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 23:41:54 -0800 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Sun, 26 Jan 2025 23:41:54 -0800 Received: from 5810.caveonetworks.com (unknown [10.29.45.105]) by maili.marvell.com (Postfix) with ESMTP id EABC45B695A; Sun, 26 Jan 2025 23:41:51 -0800 (PST) From: Kommula Shiva Shankar To: , , CC: , , , , Subject: [PATCH v2] net/virtio: add virtio hash report feature Date: Mon, 27 Jan 2025 13:11:50 +0530 Message-ID: <20250127074150.3499851-1-kshankar@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250126193404.3431544-1-kshankar@marvell.com> References: <20250126193404.3431544-1-kshankar@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: YxsVRns1zRwmfZ_nRY2JNXnl3KIzGBOn X-Proofpoint-ORIG-GUID: YxsVRns1zRwmfZ_nRY2JNXnl3KIzGBOn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_03,2025-01-27_01,2024-11-22_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch adds virtio hash report feature, which is supported in packet queue mode with scalar version Signed-off-by: Kommula Shiva Shankar --- drivers/net/virtio/virtio.h | 2 ++ drivers/net/virtio/virtio_ethdev.c | 20 ++++++++++++- drivers/net/virtio/virtio_ethdev.h | 1 + drivers/net/virtio/virtio_rxtx.c | 30 +++++++++++++++++++ .../net/virtio/virtio_user/virtio_user_dev.c | 1 + drivers/net/virtio/virtqueue.h | 21 +++++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio/virtio.h b/drivers/net/virtio/virtio.h index ef5827c5f5..c2a0fd477c 100644 --- a/drivers/net/virtio/virtio.h +++ b/drivers/net/virtio/virtio.h @@ -30,6 +30,7 @@ #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 */ +#define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ #define VIRTIO_NET_F_RSS 60 /* RSS supported */ /* @@ -187,6 +188,7 @@ struct virtio_hw { uint8_t started; uint8_t weak_barriers; uint8_t vlan_strip; + uint8_t has_hash_report; bool rx_ol_scatter; uint8_t has_tx_offload; uint8_t has_rx_offload; diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 70d4839def..caacbce57a 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -1796,7 +1796,9 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features) eth_dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC; /* Setting up rx_header size for the device */ - if (virtio_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) || + if (virtio_with_feature(hw, VIRTIO_NET_F_HASH_REPORT)) + hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr_hash_report); + else if (virtio_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) || virtio_with_feature(hw, VIRTIO_F_VERSION_1) || virtio_with_packed_queue(hw)) hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr_mrg_rxbuf); @@ -2181,6 +2183,10 @@ virtio_dev_configure(struct rte_eth_dev *dev) (1ULL << VIRTIO_NET_F_GUEST_TSO4) | (1ULL << VIRTIO_NET_F_GUEST_TSO6); + if (rx_offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH) + req_features |= + (1ULL << VIRTIO_NET_F_HASH_REPORT); + if (tx_offloads & (RTE_ETH_TX_OFFLOAD_UDP_CKSUM | RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) req_features |= (1ULL << VIRTIO_NET_F_CSUM); @@ -2233,6 +2239,9 @@ virtio_dev_configure(struct rte_eth_dev *dev) if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) hw->vlan_strip = 1; + if (rx_offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH) + hw->has_hash_report = 1; + hw->rx_ol_scatter = (rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER); if ((rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) && @@ -2285,6 +2294,12 @@ virtio_dev_configure(struct rte_eth_dev *dev) "disabled packed ring vectorized rx for TCP_LRO enabled"); hw->use_vec_rx = 0; } + + if (rx_offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH) { + PMD_DRV_LOG(INFO, + "disabled packed ring vectorized rx for RSS_HASH enabled"); + hw->use_vec_rx = 0; + } } } else { if (virtio_with_feature(hw, VIRTIO_F_IN_ORDER)) { @@ -2669,6 +2684,9 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) dev_info->flow_type_rss_offloads = 0; } + if (host_features & (1ULL << VIRTIO_NET_F_HASH_REPORT)) + dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_RSS_HASH; + if (host_features & (1ULL << VIRTIO_F_RING_PACKED)) { /* * According to 2.7 Packed Virtqueues, diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h index 7be1c9acd0..7aa771fd2b 100644 --- a/drivers/net/virtio/virtio_ethdev.h +++ b/drivers/net/virtio/virtio_ethdev.h @@ -46,6 +46,7 @@ 1u << VIRTIO_NET_F_CSUM | \ 1u << VIRTIO_NET_F_HOST_TSO4 | \ 1u << VIRTIO_NET_F_HOST_TSO6 | \ + 1ULL << VIRTIO_NET_F_HASH_REPORT | \ 1ULL << VIRTIO_NET_F_RSS) extern const struct eth_dev_ops virtio_user_secondary_eth_dev_ops; diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index b67f063b31..35bd61350c 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -40,6 +40,19 @@ #define VIRTIO_DUMP_PACKET(m, len) do { } while (0) #endif +static const uint32_t vhdr_hash_report_to_mbuf_pkt_type[] = { + RTE_PTYPE_UNKNOWN, + RTE_PTYPE_L3_IPV4, + RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP, + RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP, + RTE_PTYPE_L3_IPV6, + RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP, + RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP, + RTE_PTYPE_L3_IPV6_EXT, + RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_TCP, + RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_UDP, +}; + void vq_ring_free_inorder(struct virtqueue *vq, uint16_t desc_idx, uint16_t num) { @@ -901,6 +914,16 @@ virtio_discard_rxbuf_inorder(struct virtqueue *vq, struct rte_mbuf *m) } } +static inline void +virtio_rx_update_hash_report(struct rte_mbuf *m, struct virtio_net_hdr_hash_report *hdr) +{ + if (likely(hdr->hash_report)) { + m->packet_type = vhdr_hash_report_to_mbuf_pkt_type[hdr->hash_report]; + m->hash.rss = hdr->hash_value; + m->ol_flags |= RTE_MBUF_F_RX_RSS_HASH; + } +} + /* Optionally fill offload information in structure */ static inline int virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr) @@ -1134,6 +1157,9 @@ virtio_recv_pkts_packed(void *rx_queue, struct rte_mbuf **rx_pkts, hdr = (struct virtio_net_hdr *)((char *)rxm->buf_addr + RTE_PKTMBUF_HEADROOM - hdr_size); + if (hw->has_hash_report) + virtio_rx_update_hash_report(rxm, + (struct virtio_net_hdr_hash_report *)hdr); if (hw->vlan_strip) rte_vlan_strip(rxm); @@ -1617,6 +1643,10 @@ virtio_recv_mergeable_pkts_packed(void *rx_queue, if (hw->vlan_strip) rte_vlan_strip(rx_pkts[nb_rx]); + if (hw->has_hash_report) + virtio_rx_update_hash_report(rxm, + (struct virtio_net_hdr_hash_report *)header); + seg_res = seg_num - 1; /* Merge remaining segments */ diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 2997d2bd26..187f81b066 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -726,6 +726,7 @@ virtio_user_free_vrings(struct virtio_user_dev *dev) 1ULL << VIRTIO_F_RING_PACKED | \ 1ULL << VIRTIO_F_NOTIFICATION_DATA | \ 1ULL << VIRTIO_F_ORDER_PLATFORM | \ + 1ULL << VIRTIO_NET_F_HASH_REPORT | \ 1ULL << VIRTIO_NET_F_RSS) int diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h index 60211a40c9..3b468bd4f4 100644 --- a/drivers/net/virtio/virtqueue.h +++ b/drivers/net/virtio/virtqueue.h @@ -257,6 +257,27 @@ struct virtio_net_hdr_mrg_rxbuf { uint16_t num_buffers; /**< Number of merged rx buffers */ }; +/** + * This is the version of the header to use when the HASH_REPORT + * feature has been negotiated. + */ +struct virtio_net_hdr_hash_report { + struct virtio_net_hdr_mrg_rxbuf hdr; + uint32_t hash_value; +#define VIRTIO_NET_HASH_REPORT_NONE 0 +#define VIRTIO_NET_HASH_REPORT_IPV4 1 +#define VIRTIO_NET_HASH_REPORT_TCPV4 2 +#define VIRTIO_NET_HASH_REPORT_UDPV4 3 +#define VIRTIO_NET_HASH_REPORT_IPV6 4 +#define VIRTIO_NET_HASH_REPORT_TCPV6 5 +#define VIRTIO_NET_HASH_REPORT_UDPV6 6 +#define VIRTIO_NET_HASH_REPORT_IPV6_EX 7 +#define VIRTIO_NET_HASH_REPORT_TCPV6_EX 8 +#define VIRTIO_NET_HASH_REPORT_UDPV6_EX 9 + uint16_t hash_report; + uint16_t pad_reserved; +}; + /* Region reserved to allow for transmit header and indirect ring */ #define VIRTIO_MAX_TX_INDIRECT 8 struct virtio_tx_region { -- 2.43.0