DPDK patches and discussions
 help / color / mirror / Atom feed
From: Yanling Song <songyl@ramaxel.com>
To: <dev@dpdk.org>
Cc: <songyl@ramaxel.com>, <yanling.song@linux.dev>,
	<yanggan@ramaxel.com>, <xuyun@ramaxel.com>,
	<ferruh.yigit@intel.com>, <stephen@networkplumber.org>,
	<lihuisong@huawei.com>
Subject: [PATCH v6 17/26] net/spnic: support RSS configuration update and get
Date: Thu, 30 Dec 2021 14:08:55 +0800	[thread overview]
Message-ID: <1065065361175ff09867cdeaf6be2c375d3507aa.1640838702.git.songyl@ramaxel.com> (raw)
In-Reply-To: <cover.1640838702.git.songyl@ramaxel.com>

This commit implements rss_hash_update and rss_hash_conf_get.

Signed-off-by: Yanling Song <songyl@ramaxel.com>
---
 drivers/net/spnic/spnic_ethdev.c | 235 +++++++++++++++++++++++++++++++
 1 file changed, 235 insertions(+)

diff --git a/drivers/net/spnic/spnic_ethdev.c b/drivers/net/spnic/spnic_ethdev.c
index 531a094445..b0903b65fb 100644
--- a/drivers/net/spnic/spnic_ethdev.c
+++ b/drivers/net/spnic/spnic_ethdev.c
@@ -1258,6 +1258,233 @@ static int spnic_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 	return err;
 }
 
+
+/**
+ * Update the RSS hash key and RSS hash type.
+ *
+ * @param[in] dev
+ *   Pointer to ethernet device structure.
+ * @param[in] rss_conf
+ *   RSS configuration data.
+ *
+ * @retval zero: Success
+ * @retval non-zero: Failure
+ */
+static int spnic_rss_hash_update(struct rte_eth_dev *dev,
+				 struct rte_eth_rss_conf *rss_conf)
+{
+	struct spnic_nic_dev *nic_dev = SPNIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct spnic_rss_type rss_type = {0};
+	u64 rss_hf = rss_conf->rss_hf;
+	int err = 0;
+
+	if (nic_dev->rss_state == SPNIC_RSS_DISABLE) {
+		if (rss_hf != 0)
+			return -EINVAL;
+
+		PMD_DRV_LOG(INFO, "RSS is not enabled");
+		return 0;
+	}
+
+	if (rss_conf->rss_key_len > SPNIC_RSS_KEY_SIZE) {
+		PMD_DRV_LOG(ERR, "Invalid RSS key, rss_key_len: %d",
+			    rss_conf->rss_key_len);
+		return -EINVAL;
+	}
+
+	if (rss_conf->rss_key) {
+		err = spnic_rss_set_hash_key(nic_dev->hwdev, nic_dev->rss_key);
+		if (err) {
+			PMD_DRV_LOG(ERR, "Set RSS hash key failed");
+			return err;
+		}
+		memcpy(nic_dev->rss_key, rss_conf->rss_key,
+		       rss_conf->rss_key_len);
+	}
+
+	rss_type.ipv4 = (rss_hf & (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
+		ETH_RSS_NONFRAG_IPV4_OTHER)) ? 1 : 0;
+	rss_type.tcp_ipv4 = (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) ? 1 : 0;
+	rss_type.ipv6 = (rss_hf & (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
+		ETH_RSS_NONFRAG_IPV6_OTHER)) ? 1 : 0;
+	rss_type.ipv6_ext = (rss_hf & ETH_RSS_IPV6_EX) ? 1 : 0;
+	rss_type.tcp_ipv6 = (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) ? 1 : 0;
+	rss_type.tcp_ipv6_ext = (rss_hf & ETH_RSS_IPV6_TCP_EX) ? 1 : 0;
+	rss_type.udp_ipv4 = (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) ? 1 : 0;
+	rss_type.udp_ipv6 = (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP) ? 1 : 0;
+
+	err = spnic_set_rss_type(nic_dev->hwdev, rss_type);
+	if (err)
+		PMD_DRV_LOG(ERR, "Set RSS type failed");
+
+	return err;
+}
+
+/**
+ * Get the RSS hash configuration.
+ *
+ * @param[in] dev
+ *   Pointer to ethernet device structure.
+ * @param[out] rss_conf
+ *   RSS configuration data.
+ *
+ * @retval zero: Success
+ * @retval non-zero: Failure
+ */
+static int spnic_rss_conf_get(struct rte_eth_dev *dev,
+			      struct rte_eth_rss_conf *rss_conf)
+{
+	struct spnic_nic_dev *nic_dev = SPNIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct spnic_rss_type rss_type = {0};
+	int err;
+
+	if (!rss_conf)
+		return -EINVAL;
+
+	if (nic_dev->rss_state == SPNIC_RSS_DISABLE) {
+		rss_conf->rss_hf = 0;
+		PMD_DRV_LOG(INFO, "RSS is not enabled");
+		return 0;
+	}
+
+	if (rss_conf->rss_key &&
+	    rss_conf->rss_key_len >= SPNIC_RSS_KEY_SIZE) {
+		/*
+		 * Get RSS key from driver to reduce the frequency of the MPU
+		 * accessing the RSS memory.
+		 */
+		rss_conf->rss_key_len = sizeof(nic_dev->rss_key);
+		memcpy(rss_conf->rss_key, nic_dev->rss_key,
+		       rss_conf->rss_key_len);
+	}
+
+	err = spnic_get_rss_type(nic_dev->hwdev, &rss_type);
+	if (err)
+		return err;
+
+	rss_conf->rss_hf = 0;
+	rss_conf->rss_hf |=  rss_type.ipv4 ? (ETH_RSS_IPV4 |
+		ETH_RSS_FRAG_IPV4 | ETH_RSS_NONFRAG_IPV4_OTHER) : 0;
+	rss_conf->rss_hf |=  rss_type.tcp_ipv4 ? ETH_RSS_NONFRAG_IPV4_TCP : 0;
+	rss_conf->rss_hf |=  rss_type.ipv6 ? (ETH_RSS_IPV6 |
+		ETH_RSS_FRAG_IPV6 | ETH_RSS_NONFRAG_IPV6_OTHER) : 0;
+	rss_conf->rss_hf |=  rss_type.ipv6_ext ? ETH_RSS_IPV6_EX : 0;
+	rss_conf->rss_hf |=  rss_type.tcp_ipv6 ? ETH_RSS_NONFRAG_IPV6_TCP : 0;
+	rss_conf->rss_hf |=  rss_type.tcp_ipv6_ext ? ETH_RSS_IPV6_TCP_EX : 0;
+	rss_conf->rss_hf |=  rss_type.udp_ipv4 ? ETH_RSS_NONFRAG_IPV4_UDP : 0;
+	rss_conf->rss_hf |=  rss_type.udp_ipv6 ? ETH_RSS_NONFRAG_IPV6_UDP : 0;
+
+	return 0;
+}
+
+/**
+ * Get the RETA indirection table.
+ *
+ * @param[in] dev
+ *   Pointer to ethernet device structure.
+ * @param[out] reta_conf
+ *   Pointer to RETA configuration structure array.
+ * @param[in] reta_size
+ *   Size of the RETA table.
+ *
+ * @retval zero: Success
+ * @retval non-zero: Failure
+ */
+static int spnic_rss_reta_query(struct rte_eth_dev *dev,
+				struct rte_eth_rss_reta_entry64 *reta_conf,
+				uint16_t reta_size)
+{
+	struct spnic_nic_dev *nic_dev = SPNIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u32 indirtbl[SPNIC_RSS_INDIR_SIZE] = {0};
+	u16 idx, shift;
+	u16 i;
+	int err;
+
+	if (nic_dev->rss_state == SPNIC_RSS_DISABLE) {
+		PMD_DRV_LOG(INFO, "RSS is not enabled");
+		return 0;
+	}
+
+	if (reta_size != SPNIC_RSS_INDIR_SIZE) {
+		PMD_DRV_LOG(ERR, "Invalid reta size, reta_size: %d", reta_size);
+		return -EINVAL;
+	}
+
+	err = spnic_rss_get_indir_tbl(nic_dev->hwdev, indirtbl);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Get RSS retas table failed, error: %d",
+			    err);
+		return err;
+	}
+
+	for (i = 0; i < reta_size; i++) {
+		idx = i / RTE_RETA_GROUP_SIZE;
+		shift = i % RTE_RETA_GROUP_SIZE;
+		if (reta_conf[idx].mask & (1ULL << shift))
+			reta_conf[idx].reta[shift] = (uint16_t)indirtbl[i];
+	}
+
+	return 0;
+}
+
+/**
+ * Update the RETA indirection table.
+ *
+ * @param[in] dev
+ *   Pointer to ethernet device structure.
+ * @param[in] reta_conf
+ *   Pointer to RETA configuration structure array.
+ * @param[in] reta_size
+ *   Size of the RETA table.
+ *
+ * @retval zero: Success
+ * @retval non-zero: Failure
+ */
+static int spnic_rss_reta_update(struct rte_eth_dev *dev,
+				 struct rte_eth_rss_reta_entry64 *reta_conf,
+				 uint16_t reta_size)
+{
+	struct spnic_nic_dev *nic_dev = SPNIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u32 indirtbl[SPNIC_RSS_INDIR_SIZE] = {0};
+	u16 idx, shift;
+	u16 i;
+	int err;
+
+	if (nic_dev->rss_state == SPNIC_RSS_DISABLE)
+		return 0;
+
+	if (reta_size != SPNIC_RSS_INDIR_SIZE) {
+		PMD_DRV_LOG(ERR, "Invalid reta size, reta_size: %d", reta_size);
+		return -EINVAL;
+	}
+
+	err = spnic_rss_get_indir_tbl(nic_dev->hwdev, indirtbl);
+	if (err)
+		return err;
+
+	/* Update RSS reta table */
+	for (i = 0; i < reta_size; i++) {
+		idx = i / RTE_RETA_GROUP_SIZE;
+		shift = i % RTE_RETA_GROUP_SIZE;
+		if (reta_conf[idx].mask & (1ULL << shift))
+			indirtbl[i] = reta_conf[idx].reta[shift];
+	}
+
+	for (i = 0 ; i < reta_size; i++) {
+		if (indirtbl[i] >= nic_dev->num_rqs) {
+			PMD_DRV_LOG(ERR, "Invalid reta entry, index: %d, num_rqs: %d",
+				    indirtbl[i], nic_dev->num_rqs);
+			return -EFAULT;
+		}
+	}
+
+	err = spnic_rss_set_indir_tbl(nic_dev->hwdev, indirtbl);
+	if (err)
+		PMD_DRV_LOG(ERR, "Set RSS reta table failed");
+
+	return err;
+}
+
 /**
  * Update MAC address
  *
@@ -1465,6 +1692,10 @@ static const struct eth_dev_ops spnic_pmd_ops = {
 	.dev_stop                      = spnic_dev_stop,
 	.dev_close                     = spnic_dev_close,
 	.mtu_set                       = spnic_dev_set_mtu,
+	.rss_hash_update               = spnic_rss_hash_update,
+	.rss_hash_conf_get             = spnic_rss_conf_get,
+	.reta_update                   = spnic_rss_reta_update,
+	.reta_query                    = spnic_rss_reta_query,
 	.mac_addr_set                  = spnic_set_mac_addr,
 	.mac_addr_remove               = spnic_mac_addr_remove,
 	.mac_addr_add                  = spnic_mac_addr_add,
@@ -1484,6 +1715,10 @@ static const struct eth_dev_ops spnic_pmd_vf_ops = {
 	.dev_stop                      = spnic_dev_stop,
 	.dev_close                     = spnic_dev_close,
 	.mtu_set                       = spnic_dev_set_mtu,
+	.rss_hash_update               = spnic_rss_hash_update,
+	.rss_hash_conf_get             = spnic_rss_conf_get,
+	.reta_update                   = spnic_rss_reta_update,
+	.reta_query                    = spnic_rss_reta_query,
 	.mac_addr_set                  = spnic_set_mac_addr,
 	.mac_addr_remove               = spnic_mac_addr_remove,
 	.mac_addr_add                  = spnic_mac_addr_add,
-- 
2.32.0


  parent reply	other threads:[~2021-12-30  6:11 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-30  6:08 [PATCH v6 00/26] Net/SPNIC: support SPNIC into DPDK 22.03 Yanling Song
2021-12-30  6:08 ` [PATCH v6 01/26] drivers/net: introduce a new PMD driver Yanling Song
2022-01-19 16:58   ` Ferruh Yigit
2021-12-30  6:08 ` [PATCH v6 02/26] net/spnic: initialize the HW interface Yanling Song
2022-01-19 17:05   ` Ferruh Yigit
2022-01-21  9:32     ` Yanling Song
2021-12-30  6:08 ` [PATCH v6 03/26] net/spnic: add mbox message channel Yanling Song
2021-12-30  6:08 ` [PATCH v6 04/26] net/spnic: introduce event queue Yanling Song
2021-12-30  6:08 ` [PATCH v6 05/26] net/spnic: add mgmt module Yanling Song
2022-01-19 17:22   ` Ferruh Yigit
2022-01-21  9:33     ` Yanling Song
2021-12-30  6:08 ` [PATCH v6 06/26] net/spnic: add cmdq and work queue Yanling Song
2021-12-30  6:08 ` [PATCH v6 07/26] net/spnic: add interface handling cmdq message Yanling Song
2021-12-30  6:08 ` [PATCH v6 08/26] net/spnic: add hardware info initialization Yanling Song
2021-12-30  6:08 ` [PATCH v6 09/26] net/spnic: support MAC and link event handling Yanling Song
2022-01-19 17:26   ` Ferruh Yigit
2022-01-21  9:36     ` Yanling Song
2021-12-30  6:08 ` [PATCH v6 10/26] net/spnic: add function info initialization Yanling Song
2021-12-30  6:08 ` [PATCH v6 11/26] net/spnic: add queue pairs context initialization Yanling Song
2021-12-30  6:08 ` [PATCH v6 12/26] net/spnic: support mbuf handling of Tx/Rx Yanling Song
2021-12-30  6:08 ` [PATCH v6 13/26] net/spnic: support Rx congfiguration Yanling Song
2021-12-30  6:08 ` [PATCH v6 14/26] net/spnic: add port/vport enable Yanling Song
2021-12-30  6:08 ` [PATCH v6 15/26] net/spnic: support IO packets handling Yanling Song
2021-12-30  6:08 ` [PATCH v6 16/26] net/spnic: add device configure/version/info Yanling Song
2021-12-30  6:08 ` Yanling Song [this message]
2021-12-30  6:08 ` [PATCH v6 18/26] net/spnic: support VLAN filtering and offloading Yanling Song
2021-12-30  6:08 ` [PATCH v6 19/26] net/spnic: support promiscuous and allmulticast Rx modes Yanling Song
2021-12-30  6:08 ` [PATCH v6 20/26] net/spnic: support flow control Yanling Song
2021-12-30  6:08 ` [PATCH v6 21/26] net/spnic: support getting Tx/Rx queues info Yanling Song
2021-12-30  6:09 ` [PATCH v6 22/26] net/spnic: net/spnic: support xstats statistics Yanling Song
2021-12-30  6:09 ` [PATCH v6 23/26] net/spnic: support VFIO interrupt Yanling Song
2021-12-30  6:09 ` [PATCH v6 24/26] net/spnic: support Tx/Rx queue start/stop Yanling Song
2021-12-30  6:09 ` [PATCH v6 25/26] net/spnic: add doc infrastructure Yanling Song
2022-01-19 17:27   ` Ferruh Yigit
2022-01-21  9:39     ` Yanling Song
2021-12-30  6:09 ` [PATCH v6 26/26] net/spnic: fixes unsafe C style code Yanling Song
2022-01-19 17:28   ` Ferruh Yigit
2022-01-21  9:40     ` Yanling Song
2022-01-19 16:56 ` [PATCH v6 00/26] Net/SPNIC: support SPNIC into DPDK 22.03 Ferruh Yigit
2022-01-21  9:27   ` Yanling Song
2022-01-21 10:22     ` Ferruh Yigit
2022-01-24  5:12       ` Hemant Agrawal
2022-02-12 14:01       ` Yanling Song
2022-02-13 18:07         ` Thomas Monjalon
2022-02-18  9:30           ` Yanling Song
2023-04-13  9:02             ` Ferruh Yigit
2023-07-31 14:08               ` Thomas Monjalon
2022-02-16 14:19         ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1065065361175ff09867cdeaf6be2c375d3507aa.1640838702.git.songyl@ramaxel.com \
    --to=songyl@ramaxel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=lihuisong@huawei.com \
    --cc=stephen@networkplumber.org \
    --cc=xuyun@ramaxel.com \
    --cc=yanggan@ramaxel.com \
    --cc=yanling.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).