All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] net/e1000: move RSS to flow API
@ 2017-11-23  9:03 Wei Zhao
  2017-11-23  9:03 ` [PATCH 2/2] net/ixgbe: " Wei Zhao
  2017-11-24  3:10 ` [PATCH v2 0/2] " Wei Zhao
  0 siblings, 2 replies; 28+ messages in thread
From: Wei Zhao @ 2017-11-23  9:03 UTC (permalink / raw)
  To: dev; +Cc: Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move igb existing RSS to rte_flow.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
---
 drivers/net/e1000/e1000_ethdev.h |  20 +++++
 drivers/net/e1000/igb_ethdev.c   |  16 ++++
 drivers/net/e1000/igb_flow.c     | 160 +++++++++++++++++++++++++++++++++++++++
 drivers/net/e1000/igb_rxtx.c     |  61 +++++++++++++++
 4 files changed, 257 insertions(+)

diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index 5668910..0731766 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -257,6 +257,12 @@ struct igb_ethertype_filter {
 	uint32_t etqf;
 };
 
+struct igb_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IGB_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /*
  * Structure to store filters'info.
  */
@@ -274,6 +280,8 @@ struct e1000_filter_info {
 	struct e1000_2tuple_filter_list twotuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct igb_rte_flow_rss_conf rss_info;
 };
 
 /*
@@ -342,6 +350,12 @@ struct igb_flex_filter_ele {
 	struct rte_eth_flex_filter filter_info;
 };
 
+/* rss filter  list structure */
+struct igb_rss_conf_ele {
+	TAILQ_ENTRY(igb_rss_conf_ele) entries;
+	struct igb_rte_flow_rss_conf filter_info;
+};
+
 /* igb_flow memory list structure */
 struct igb_flow_mem {
 	TAILQ_ENTRY(igb_flow_mem) entries;
@@ -357,6 +371,8 @@ TAILQ_HEAD(igb_syn_filter_list, igb_eth_syn_filter_ele);
 struct igb_syn_filter_list igb_filter_syn_list;
 TAILQ_HEAD(igb_flex_filter_list, igb_flex_filter_ele);
 struct igb_flex_filter_list igb_filter_flex_list;
+TAILQ_HEAD(igb_rss_filter_list, igb_rss_conf_ele);
+struct igb_rss_filter_list igb_filter_rss_list;
 TAILQ_HEAD(igb_flow_mem_list, igb_flow_mem);
 struct igb_flow_mem_list igb_flow_list;
 
@@ -500,4 +516,8 @@ int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
 int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
 			struct rte_eth_flex_filter *filter,
 			bool add);
+int igb_config_rss_filter(struct rte_eth_dev *dev,
+			struct igb_rte_flow_rss_conf *conf,
+			bool add);
+
 #endif /* _E1000_ETHDEV_H_ */
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index fdc139f..2faa089 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -948,6 +948,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 	TAILQ_INIT(&igb_filter_ethertype_list);
 	TAILQ_INIT(&igb_filter_syn_list);
 	TAILQ_INIT(&igb_filter_flex_list);
+	TAILQ_INIT(&igb_filter_rss_list);
 	TAILQ_INIT(&igb_flow_list);
 
 	return 0;
@@ -1007,6 +1008,10 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 	memset(filter_info->ethertype_filters, 0,
 		E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
 
+	/* clear the rss filter info */
+	memset(&filter_info->rss_info, 0,
+		sizeof(struct igb_rte_flow_rss_conf));
+
 	/* remove all ntuple filters of the device */
 	igb_ntuple_filter_uninit(eth_dev);
 
@@ -5628,6 +5633,16 @@ igb_flex_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+igb_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	igb_config_rss_filter(dev, &filter_info->rss_info, TRUE);
+}
+
 /* restore all types filter */
 static int
 igb_filter_restore(struct rte_eth_dev *dev)
@@ -5636,6 +5651,7 @@ igb_filter_restore(struct rte_eth_dev *dev)
 	igb_ethertype_filter_restore(dev);
 	igb_syn_filter_restore(dev);
 	igb_flex_filter_restore(dev);
+	igb_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/e1000/igb_flow.c b/drivers/net/e1000/igb_flow.c
index 22bad26..840f814 100644
--- a/drivers/net/e1000/igb_flow.c
+++ b/drivers/net/e1000/igb_flow.c
@@ -1295,6 +1295,101 @@ igb_parse_flex_filter(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+igb_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct igb_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n, index;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	index = 0;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	index++;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
 /**
  * Create a flow rule.
  * Theorically one rule can match more than one filters.
@@ -1313,11 +1408,13 @@ igb_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct igb_ntuple_filter_ele *ntuple_filter_ptr;
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 
 	flow = rte_zmalloc("igb_rte_flow", sizeof(struct rte_flow), 0);
@@ -1419,6 +1516,29 @@ igb_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = igb_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("igb_rss_filter",
+				sizeof(struct igb_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct igb_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&igb_flow_list,
 		igb_flow_mem_ptr, entries);
@@ -1446,6 +1566,7 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -1469,6 +1590,12 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	memset(&flex_filter, 0, sizeof(struct rte_eth_flex_filter));
 	ret = igb_parse_flex_filter(dev, attr, pattern,
 				actions, &flex_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -1487,6 +1614,7 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -1533,6 +1661,17 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(flex_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct igb_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = igb_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -1621,6 +1760,17 @@ igb_clear_all_flex_filter(struct rte_eth_dev *dev)
 		igb_remove_flex_filter(dev, flex_filter);
 }
 
+/* remove the rss filter */
+static void
+igb_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter->rss_info.num)
+		igb_config_rss_filter(dev, &filter->rss_info, FALSE);
+}
+
 void
 igb_filterlist_flush(struct rte_eth_dev *dev)
 {
@@ -1628,6 +1778,7 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele  *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 	enum rte_filter_type filter_type;
 	struct rte_flow *pmd_flow;
@@ -1670,6 +1821,14 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 						flex_filter_ptr, entries);
 				rte_free(flex_filter_ptr);
 				break;
+			case RTE_ETH_FILTER_HASH:
+				rss_filter_ptr =
+					(struct igb_rss_conf_ele *)
+						pmd_flow->rule;
+				TAILQ_REMOVE(&igb_filter_rss_list,
+						rss_filter_ptr, entries);
+				rte_free(rss_filter_ptr);
+				break;	
 			default:
 				PMD_DRV_LOG(WARNING, "Filter type"
 					"(%d) not supported", filter_type);
@@ -1693,6 +1852,7 @@ igb_flow_flush(struct rte_eth_dev *dev,
 	igb_clear_all_ethertype_filter(dev);
 	igb_clear_syn_filter(dev);
 	igb_clear_all_flex_filter(dev);
+	igb_clear_rss_filter(dev);
 	igb_filterlist_flush(dev);
 
 	return 0;
diff --git a/drivers/net/e1000/igb_rxtx.c b/drivers/net/e1000/igb_rxtx.c
index 4ee12e9..af86726 100644
--- a/drivers/net/e1000/igb_rxtx.c
+++ b/drivers/net/e1000/igb_rxtx.c
@@ -2786,3 +2786,64 @@ igb_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 	qinfo->conf.tx_thresh.hthresh = txq->hthresh;
 	qinfo->conf.tx_thresh.wthresh = txq->wthresh;
 }
+
+int
+igb_config_rss_filter(struct rte_eth_dev *dev,
+		struct igb_rte_flow_rss_conf *conf, bool add)
+{
+	uint32_t shift;
+	uint16_t i, j;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct igb_rte_flow_rss_conf)) == 0) {
+			igb_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct igb_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+
+	/* Fill in redirection table. */
+	shift = (hw->mac.type == e1000_82575) ? 6 : 0;
+	for (i = 0, j = 0; i < 128; i++, j++) {
+		union e1000_reta {
+			uint32_t dword;
+			uint8_t  bytes[4];
+		} reta;
+		uint8_t q_idx;
+
+		q_idx = conf->queue[j];
+		if (j == conf->num)
+			j = 0;
+		reta.bytes[i & 3] = (uint8_t)(q_idx << shift);
+		if ((i & 3) == 3)
+			E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
+		igb_rss_disable(dev);
+		return 0;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	igb_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct igb_rte_flow_rss_conf));
+
+	return 0;
+}
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 2/2] net/ixgbe: move RSS to flow API
  2017-11-23  9:03 [PATCH 1/2] net/e1000: move RSS to flow API Wei Zhao
@ 2017-11-23  9:03 ` Wei Zhao
  2017-11-24  3:10 ` [PATCH v2 0/2] " Wei Zhao
  1 sibling, 0 replies; 28+ messages in thread
From: Wei Zhao @ 2017-11-23  9:03 UTC (permalink / raw)
  To: dev; +Cc: Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move ixgbe existing RSS to rte_flow.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
---
 drivers/net/ixgbe/ixgbe_ethdev.c |  12 +++
 drivers/net/ixgbe/ixgbe_ethdev.h |  10 +++
 drivers/net/ixgbe/ixgbe_flow.c   | 165 +++++++++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_rxtx.c   |  65 +++++++++++++++
 4 files changed, 252 insertions(+)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index ff19a56..2596f19 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -8339,6 +8339,17 @@ ixgbe_l2_tn_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+ixgbe_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	ixgbe_config_rss_filter(dev,
+			&filter_info->rss_info, TRUE);
+}
+
 static int
 ixgbe_filter_restore(struct rte_eth_dev *dev)
 {
@@ -8347,6 +8358,7 @@ ixgbe_filter_restore(struct rte_eth_dev *dev)
 	ixgbe_syn_filter_restore(dev);
 	ixgbe_fdir_filter_restore(dev);
 	ixgbe_l2_tn_filter_restore(dev);
+	ixgbe_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 51ddcfd..4af79b4 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -224,6 +224,12 @@ struct ixgbe_hw_fdir_info {
 	bool mask_added; /* If already got mask from consistent filter */
 };
 
+struct ixgbe_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IXGBE_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /* structure for interrupt relative data */
 struct ixgbe_interrupt {
 	uint32_t flags;
@@ -340,6 +346,8 @@ struct ixgbe_filter_info {
 	struct ixgbe_5tuple_filter_list fivetuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct ixgbe_rte_flow_rss_conf rss_info;
 };
 
 struct ixgbe_l2_tn_key {
@@ -719,6 +727,8 @@ void ixgbe_tm_conf_init(struct rte_eth_dev *dev);
 void ixgbe_tm_conf_uninit(struct rte_eth_dev *dev);
 int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev, uint16_t queue_idx,
 			       uint16_t tx_rate);
+int ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add);
 
 static inline int
 ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info,
diff --git a/drivers/net/ixgbe/ixgbe_flow.c b/drivers/net/ixgbe/ixgbe_flow.c
index 19c2d47..8f964cf 100644
--- a/drivers/net/ixgbe/ixgbe_flow.c
+++ b/drivers/net/ixgbe/ixgbe_flow.c
@@ -103,6 +103,11 @@ struct ixgbe_eth_l2_tunnel_conf_ele {
 	TAILQ_ENTRY(ixgbe_eth_l2_tunnel_conf_ele) entries;
 	struct rte_eth_l2_tunnel_conf filter_info;
 };
+/* rss filter list structure */
+struct ixgbe_rss_conf_ele {
+	TAILQ_ENTRY(ixgbe_rss_conf_ele) entries;
+	struct ixgbe_rte_flow_rss_conf filter_info;
+};
 /* ixgbe_flow memory list structure */
 struct ixgbe_flow_mem {
 	TAILQ_ENTRY(ixgbe_flow_mem) entries;
@@ -114,6 +119,7 @@ TAILQ_HEAD(ixgbe_ethertype_filter_list, ixgbe_ethertype_filter_ele);
 TAILQ_HEAD(ixgbe_syn_filter_list, ixgbe_eth_syn_filter_ele);
 TAILQ_HEAD(ixgbe_fdir_rule_filter_list, ixgbe_fdir_rule_ele);
 TAILQ_HEAD(ixgbe_l2_tunnel_filter_list, ixgbe_eth_l2_tunnel_conf_ele);
+TAILQ_HEAD(ixgbe_rss_filter_list, ixgbe_rss_conf_ele);
 TAILQ_HEAD(ixgbe_flow_mem_list, ixgbe_flow_mem);
 
 static struct ixgbe_ntuple_filter_list filter_ntuple_list;
@@ -121,6 +127,7 @@ static struct ixgbe_ethertype_filter_list filter_ethertype_list;
 static struct ixgbe_syn_filter_list filter_syn_list;
 static struct ixgbe_fdir_rule_filter_list filter_fdir_list;
 static struct ixgbe_l2_tunnel_filter_list filter_l2_tunnel_list;
+static struct ixgbe_rss_filter_list filter_rss_list;
 static struct ixgbe_flow_mem_list ixgbe_flow_list;
 
 /**
@@ -2700,6 +2707,109 @@ ixgbe_parse_fdir_filter(struct rte_eth_dev *dev,
 	return ret;
 }
 
+static int
+ixgbe_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct ixgbe_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	act = next_no_void_action(actions, NULL);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	act = next_no_void_action(actions, act);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
+/* remove the rss filter */
+static void
+ixgbe_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		ixgbe_config_rss_filter(dev, &filter_info->rss_info, FALSE);
+}
+
 void
 ixgbe_filterlist_init(void)
 {
@@ -2708,6 +2818,7 @@ ixgbe_filterlist_init(void)
 	TAILQ_INIT(&filter_syn_list);
 	TAILQ_INIT(&filter_fdir_list);
 	TAILQ_INIT(&filter_l2_tunnel_list);
+	TAILQ_INIT(&filter_rss_list);
 	TAILQ_INIT(&ixgbe_flow_list);
 }
 
@@ -2720,6 +2831,7 @@ ixgbe_filterlist_flush(void)
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	while ((ntuple_filter_ptr = TAILQ_FIRST(&filter_ntuple_list))) {
 		TAILQ_REMOVE(&filter_ntuple_list,
@@ -2756,6 +2868,13 @@ ixgbe_filterlist_flush(void)
 		rte_free(fdir_rule_ptr);
 	}
 
+	while ((rss_filter_ptr = TAILQ_FIRST(&filter_rss_list))) {
+		TAILQ_REMOVE(&filter_rss_list,
+				 rss_filter_ptr,
+				 entries);
+		rte_free(rss_filter_ptr);
+	}
+
 	while ((ixgbe_flow_mem_ptr = TAILQ_FIRST(&ixgbe_flow_list))) {
 		TAILQ_REMOVE(&ixgbe_flow_list,
 				 ixgbe_flow_mem_ptr,
@@ -2786,12 +2905,14 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct ixgbe_ntuple_filter_ele *ntuple_filter_ptr;
 	struct ixgbe_ethertype_filter_ele *ethertype_filter_ptr;
 	struct ixgbe_eth_syn_filter_ele *syn_filter_ptr;
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	uint8_t first_mask = FALSE;
 
@@ -2992,6 +3113,29 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = ixgbe_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("ixgbe_rss_filter",
+				sizeof(struct ixgbe_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&ixgbe_flow_list,
 		ixgbe_flow_mem_ptr, entries);
@@ -3020,6 +3164,7 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_fdir_rule fdir_rule;
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -3049,6 +3194,12 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	memset(&l2_tn_filter, 0, sizeof(struct rte_eth_l2_tunnel_conf));
 	ret = ixgbe_parse_l2_tn_filter(dev, attr, pattern,
 				actions, &l2_tn_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -3075,6 +3226,7 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -3143,6 +3295,17 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(l2_tn_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct ixgbe_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = ixgbe_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -3194,6 +3357,8 @@ ixgbe_flow_flush(struct rte_eth_dev *dev,
 		return ret;
 	}
 
+	ixgbe_clear_rss_filter(dev);
+
 	ixgbe_filterlist_flush();
 
 	return 0;
diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index 9bc8462..4b38247 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -5550,6 +5550,71 @@ ixgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
 	}
 }
 
+int
+ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add)
+{
+	struct ixgbe_hw *hw;
+	uint32_t reta;
+	uint16_t i;
+	uint16_t j;
+	uint16_t sp_reta_size;
+	uint32_t reta_reg;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	PMD_INIT_FUNC_TRACE();
+	hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct ixgbe_rte_flow_rss_conf)) == 0) {
+			ixgbe_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+	/* Fill in redirection table
+	 * The byte-swap is needed because NIC registers are in
+	 * little-endian order.
+	 */
+	reta = 0;
+	for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
+		reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
+
+		if (j == conf->num)
+			j = 0;
+		reta = (reta << 8) | conf->queue[j];
+		if ((i & 3) == 3)
+			IXGBE_WRITE_REG(hw, reta_reg,
+					rte_bswap32(reta));
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
+		ixgbe_rss_disable(dev);
+		return -EINVAL;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	ixgbe_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct ixgbe_rte_flow_rss_conf));
+
+	return 0;
+}
+
 /* Stubs needed for linkage when CONFIG_RTE_IXGBE_INC_VECTOR is set to 'n' */
 int __attribute__((weak))
 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 0/2] move RSS to flow API
  2017-11-23  9:03 [PATCH 1/2] net/e1000: move RSS to flow API Wei Zhao
  2017-11-23  9:03 ` [PATCH 2/2] net/ixgbe: " Wei Zhao
@ 2017-11-24  3:10 ` Wei Zhao
  2017-11-24  3:10   ` [PATCH v2 1/2] net/e1000: " Wei Zhao
                     ` (2 more replies)
  1 sibling, 3 replies; 28+ messages in thread
From: Wei Zhao @ 2017-11-24  3:10 UTC (permalink / raw)
  To: dev

The patches mainly finish following functions:
1) igb move RSS to flow API
2) ixgbe move RSS to flow API

v2:
-fix bug for RSS flush code.
-fix patch check warning.

root (2):
  net/e1000: move RSS to flow API
  net/ixgbe: move RSS to flow API

 drivers/net/e1000/e1000_ethdev.h |  20 +++++
 drivers/net/e1000/igb_ethdev.c   |  17 ++++
 drivers/net/e1000/igb_flow.c     | 160 +++++++++++++++++++++++++++++++++++++
 drivers/net/e1000/igb_rxtx.c     |  61 +++++++++++++++
 drivers/net/ixgbe/ixgbe_ethdev.c |  12 +++
 drivers/net/ixgbe/ixgbe_ethdev.h |  10 +++
 drivers/net/ixgbe/ixgbe_flow.c   | 165 +++++++++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_rxtx.c   |  65 +++++++++++++++
 8 files changed, 510 insertions(+)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v2 1/2] net/e1000: move RSS to flow API
  2017-11-24  3:10 ` [PATCH v2 0/2] " Wei Zhao
@ 2017-11-24  3:10   ` Wei Zhao
  2017-11-24  3:10   ` [PATCH v2 2/2] net/ixgbe: " Wei Zhao
  2017-11-24  8:05   ` [PATCH v3 0/2] " Wei Zhao
  2 siblings, 0 replies; 28+ messages in thread
From: Wei Zhao @ 2017-11-24  3:10 UTC (permalink / raw)
  To: dev; +Cc: Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move igb existing RSS to rte_flow.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
---
 drivers/net/e1000/e1000_ethdev.h |  20 +++++
 drivers/net/e1000/igb_ethdev.c   |  17 +++++
 drivers/net/e1000/igb_flow.c     | 160 +++++++++++++++++++++++++++++++++++++++
 drivers/net/e1000/igb_rxtx.c     |  61 +++++++++++++++
 4 files changed, 258 insertions(+)

diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index 5668910..0731766 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -257,6 +257,12 @@ struct igb_ethertype_filter {
 	uint32_t etqf;
 };
 
+struct igb_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IGB_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /*
  * Structure to store filters'info.
  */
@@ -274,6 +280,8 @@ struct e1000_filter_info {
 	struct e1000_2tuple_filter_list twotuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct igb_rte_flow_rss_conf rss_info;
 };
 
 /*
@@ -342,6 +350,12 @@ struct igb_flex_filter_ele {
 	struct rte_eth_flex_filter filter_info;
 };
 
+/* rss filter  list structure */
+struct igb_rss_conf_ele {
+	TAILQ_ENTRY(igb_rss_conf_ele) entries;
+	struct igb_rte_flow_rss_conf filter_info;
+};
+
 /* igb_flow memory list structure */
 struct igb_flow_mem {
 	TAILQ_ENTRY(igb_flow_mem) entries;
@@ -357,6 +371,8 @@ TAILQ_HEAD(igb_syn_filter_list, igb_eth_syn_filter_ele);
 struct igb_syn_filter_list igb_filter_syn_list;
 TAILQ_HEAD(igb_flex_filter_list, igb_flex_filter_ele);
 struct igb_flex_filter_list igb_filter_flex_list;
+TAILQ_HEAD(igb_rss_filter_list, igb_rss_conf_ele);
+struct igb_rss_filter_list igb_filter_rss_list;
 TAILQ_HEAD(igb_flow_mem_list, igb_flow_mem);
 struct igb_flow_mem_list igb_flow_list;
 
@@ -500,4 +516,8 @@ int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
 int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
 			struct rte_eth_flex_filter *filter,
 			bool add);
+int igb_config_rss_filter(struct rte_eth_dev *dev,
+			struct igb_rte_flow_rss_conf *conf,
+			bool add);
+
 #endif /* _E1000_ETHDEV_H_ */
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index fdc139f..275fa02 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -948,6 +948,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 	TAILQ_INIT(&igb_filter_ethertype_list);
 	TAILQ_INIT(&igb_filter_syn_list);
 	TAILQ_INIT(&igb_filter_flex_list);
+	TAILQ_INIT(&igb_filter_rss_list);
 	TAILQ_INIT(&igb_flow_list);
 
 	return 0;
@@ -1007,6 +1008,10 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 	memset(filter_info->ethertype_filters, 0,
 		E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
 
+	/* clear the rss filter info */
+	memset(&filter_info->rss_info, 0,
+		sizeof(struct igb_rte_flow_rss_conf));
+
 	/* remove all ntuple filters of the device */
 	igb_ntuple_filter_uninit(eth_dev);
 
@@ -5628,6 +5633,17 @@ igb_flex_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+igb_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		igb_config_rss_filter(dev, &filter_info->rss_info, TRUE);
+}
+
 /* restore all types filter */
 static int
 igb_filter_restore(struct rte_eth_dev *dev)
@@ -5636,6 +5652,7 @@ igb_filter_restore(struct rte_eth_dev *dev)
 	igb_ethertype_filter_restore(dev);
 	igb_syn_filter_restore(dev);
 	igb_flex_filter_restore(dev);
+	igb_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/e1000/igb_flow.c b/drivers/net/e1000/igb_flow.c
index 22bad26..bf5cfac 100644
--- a/drivers/net/e1000/igb_flow.c
+++ b/drivers/net/e1000/igb_flow.c
@@ -1295,6 +1295,101 @@ igb_parse_flex_filter(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+igb_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct igb_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n, index;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	index = 0;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	index++;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
 /**
  * Create a flow rule.
  * Theorically one rule can match more than one filters.
@@ -1313,11 +1408,13 @@ igb_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct igb_ntuple_filter_ele *ntuple_filter_ptr;
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 
 	flow = rte_zmalloc("igb_rte_flow", sizeof(struct rte_flow), 0);
@@ -1419,6 +1516,29 @@ igb_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = igb_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("igb_rss_filter",
+				sizeof(struct igb_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct igb_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&igb_flow_list,
 		igb_flow_mem_ptr, entries);
@@ -1446,6 +1566,7 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -1469,6 +1590,12 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	memset(&flex_filter, 0, sizeof(struct rte_eth_flex_filter));
 	ret = igb_parse_flex_filter(dev, attr, pattern,
 				actions, &flex_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -1487,6 +1614,7 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -1533,6 +1661,17 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(flex_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct igb_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = igb_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -1621,6 +1760,17 @@ igb_clear_all_flex_filter(struct rte_eth_dev *dev)
 		igb_remove_flex_filter(dev, flex_filter);
 }
 
+/* remove the rss filter */
+static void
+igb_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter->rss_info.num)
+		igb_config_rss_filter(dev, &filter->rss_info, FALSE);
+}
+
 void
 igb_filterlist_flush(struct rte_eth_dev *dev)
 {
@@ -1628,6 +1778,7 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele  *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 	enum rte_filter_type filter_type;
 	struct rte_flow *pmd_flow;
@@ -1670,6 +1821,14 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 						flex_filter_ptr, entries);
 				rte_free(flex_filter_ptr);
 				break;
+			case RTE_ETH_FILTER_HASH:
+				rss_filter_ptr =
+					(struct igb_rss_conf_ele *)
+						pmd_flow->rule;
+				TAILQ_REMOVE(&igb_filter_rss_list,
+						rss_filter_ptr, entries);
+				rte_free(rss_filter_ptr);
+				break;
 			default:
 				PMD_DRV_LOG(WARNING, "Filter type"
 					"(%d) not supported", filter_type);
@@ -1693,6 +1852,7 @@ igb_flow_flush(struct rte_eth_dev *dev,
 	igb_clear_all_ethertype_filter(dev);
 	igb_clear_syn_filter(dev);
 	igb_clear_all_flex_filter(dev);
+	igb_clear_rss_filter(dev);
 	igb_filterlist_flush(dev);
 
 	return 0;
diff --git a/drivers/net/e1000/igb_rxtx.c b/drivers/net/e1000/igb_rxtx.c
index 4ee12e9..af86726 100644
--- a/drivers/net/e1000/igb_rxtx.c
+++ b/drivers/net/e1000/igb_rxtx.c
@@ -2786,3 +2786,64 @@ igb_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 	qinfo->conf.tx_thresh.hthresh = txq->hthresh;
 	qinfo->conf.tx_thresh.wthresh = txq->wthresh;
 }
+
+int
+igb_config_rss_filter(struct rte_eth_dev *dev,
+		struct igb_rte_flow_rss_conf *conf, bool add)
+{
+	uint32_t shift;
+	uint16_t i, j;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct igb_rte_flow_rss_conf)) == 0) {
+			igb_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct igb_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+
+	/* Fill in redirection table. */
+	shift = (hw->mac.type == e1000_82575) ? 6 : 0;
+	for (i = 0, j = 0; i < 128; i++, j++) {
+		union e1000_reta {
+			uint32_t dword;
+			uint8_t  bytes[4];
+		} reta;
+		uint8_t q_idx;
+
+		q_idx = conf->queue[j];
+		if (j == conf->num)
+			j = 0;
+		reta.bytes[i & 3] = (uint8_t)(q_idx << shift);
+		if ((i & 3) == 3)
+			E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
+		igb_rss_disable(dev);
+		return 0;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	igb_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct igb_rte_flow_rss_conf));
+
+	return 0;
+}
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 2/2] net/ixgbe: move RSS to flow API
  2017-11-24  3:10 ` [PATCH v2 0/2] " Wei Zhao
  2017-11-24  3:10   ` [PATCH v2 1/2] net/e1000: " Wei Zhao
@ 2017-11-24  3:10   ` Wei Zhao
  2017-11-24  8:05   ` [PATCH v3 0/2] " Wei Zhao
  2 siblings, 0 replies; 28+ messages in thread
From: Wei Zhao @ 2017-11-24  3:10 UTC (permalink / raw)
  To: dev; +Cc: Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move ixgbe existing RSS to rte_flow.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
---
 drivers/net/ixgbe/ixgbe_ethdev.c |  12 +++
 drivers/net/ixgbe/ixgbe_ethdev.h |  10 +++
 drivers/net/ixgbe/ixgbe_flow.c   | 165 +++++++++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_rxtx.c   |  65 +++++++++++++++
 4 files changed, 252 insertions(+)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index ff19a56..2596f19 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -8339,6 +8339,17 @@ ixgbe_l2_tn_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+ixgbe_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	ixgbe_config_rss_filter(dev,
+			&filter_info->rss_info, TRUE);
+}
+
 static int
 ixgbe_filter_restore(struct rte_eth_dev *dev)
 {
@@ -8347,6 +8358,7 @@ ixgbe_filter_restore(struct rte_eth_dev *dev)
 	ixgbe_syn_filter_restore(dev);
 	ixgbe_fdir_filter_restore(dev);
 	ixgbe_l2_tn_filter_restore(dev);
+	ixgbe_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 51ddcfd..4af79b4 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -224,6 +224,12 @@ struct ixgbe_hw_fdir_info {
 	bool mask_added; /* If already got mask from consistent filter */
 };
 
+struct ixgbe_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IXGBE_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /* structure for interrupt relative data */
 struct ixgbe_interrupt {
 	uint32_t flags;
@@ -340,6 +346,8 @@ struct ixgbe_filter_info {
 	struct ixgbe_5tuple_filter_list fivetuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct ixgbe_rte_flow_rss_conf rss_info;
 };
 
 struct ixgbe_l2_tn_key {
@@ -719,6 +727,8 @@ void ixgbe_tm_conf_init(struct rte_eth_dev *dev);
 void ixgbe_tm_conf_uninit(struct rte_eth_dev *dev);
 int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev, uint16_t queue_idx,
 			       uint16_t tx_rate);
+int ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add);
 
 static inline int
 ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info,
diff --git a/drivers/net/ixgbe/ixgbe_flow.c b/drivers/net/ixgbe/ixgbe_flow.c
index 19c2d47..8f964cf 100644
--- a/drivers/net/ixgbe/ixgbe_flow.c
+++ b/drivers/net/ixgbe/ixgbe_flow.c
@@ -103,6 +103,11 @@ struct ixgbe_eth_l2_tunnel_conf_ele {
 	TAILQ_ENTRY(ixgbe_eth_l2_tunnel_conf_ele) entries;
 	struct rte_eth_l2_tunnel_conf filter_info;
 };
+/* rss filter list structure */
+struct ixgbe_rss_conf_ele {
+	TAILQ_ENTRY(ixgbe_rss_conf_ele) entries;
+	struct ixgbe_rte_flow_rss_conf filter_info;
+};
 /* ixgbe_flow memory list structure */
 struct ixgbe_flow_mem {
 	TAILQ_ENTRY(ixgbe_flow_mem) entries;
@@ -114,6 +119,7 @@ TAILQ_HEAD(ixgbe_ethertype_filter_list, ixgbe_ethertype_filter_ele);
 TAILQ_HEAD(ixgbe_syn_filter_list, ixgbe_eth_syn_filter_ele);
 TAILQ_HEAD(ixgbe_fdir_rule_filter_list, ixgbe_fdir_rule_ele);
 TAILQ_HEAD(ixgbe_l2_tunnel_filter_list, ixgbe_eth_l2_tunnel_conf_ele);
+TAILQ_HEAD(ixgbe_rss_filter_list, ixgbe_rss_conf_ele);
 TAILQ_HEAD(ixgbe_flow_mem_list, ixgbe_flow_mem);
 
 static struct ixgbe_ntuple_filter_list filter_ntuple_list;
@@ -121,6 +127,7 @@ static struct ixgbe_ethertype_filter_list filter_ethertype_list;
 static struct ixgbe_syn_filter_list filter_syn_list;
 static struct ixgbe_fdir_rule_filter_list filter_fdir_list;
 static struct ixgbe_l2_tunnel_filter_list filter_l2_tunnel_list;
+static struct ixgbe_rss_filter_list filter_rss_list;
 static struct ixgbe_flow_mem_list ixgbe_flow_list;
 
 /**
@@ -2700,6 +2707,109 @@ ixgbe_parse_fdir_filter(struct rte_eth_dev *dev,
 	return ret;
 }
 
+static int
+ixgbe_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct ixgbe_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	act = next_no_void_action(actions, NULL);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	act = next_no_void_action(actions, act);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
+/* remove the rss filter */
+static void
+ixgbe_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		ixgbe_config_rss_filter(dev, &filter_info->rss_info, FALSE);
+}
+
 void
 ixgbe_filterlist_init(void)
 {
@@ -2708,6 +2818,7 @@ ixgbe_filterlist_init(void)
 	TAILQ_INIT(&filter_syn_list);
 	TAILQ_INIT(&filter_fdir_list);
 	TAILQ_INIT(&filter_l2_tunnel_list);
+	TAILQ_INIT(&filter_rss_list);
 	TAILQ_INIT(&ixgbe_flow_list);
 }
 
@@ -2720,6 +2831,7 @@ ixgbe_filterlist_flush(void)
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	while ((ntuple_filter_ptr = TAILQ_FIRST(&filter_ntuple_list))) {
 		TAILQ_REMOVE(&filter_ntuple_list,
@@ -2756,6 +2868,13 @@ ixgbe_filterlist_flush(void)
 		rte_free(fdir_rule_ptr);
 	}
 
+	while ((rss_filter_ptr = TAILQ_FIRST(&filter_rss_list))) {
+		TAILQ_REMOVE(&filter_rss_list,
+				 rss_filter_ptr,
+				 entries);
+		rte_free(rss_filter_ptr);
+	}
+
 	while ((ixgbe_flow_mem_ptr = TAILQ_FIRST(&ixgbe_flow_list))) {
 		TAILQ_REMOVE(&ixgbe_flow_list,
 				 ixgbe_flow_mem_ptr,
@@ -2786,12 +2905,14 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct ixgbe_ntuple_filter_ele *ntuple_filter_ptr;
 	struct ixgbe_ethertype_filter_ele *ethertype_filter_ptr;
 	struct ixgbe_eth_syn_filter_ele *syn_filter_ptr;
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	uint8_t first_mask = FALSE;
 
@@ -2992,6 +3113,29 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = ixgbe_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("ixgbe_rss_filter",
+				sizeof(struct ixgbe_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&ixgbe_flow_list,
 		ixgbe_flow_mem_ptr, entries);
@@ -3020,6 +3164,7 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_fdir_rule fdir_rule;
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -3049,6 +3194,12 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	memset(&l2_tn_filter, 0, sizeof(struct rte_eth_l2_tunnel_conf));
 	ret = ixgbe_parse_l2_tn_filter(dev, attr, pattern,
 				actions, &l2_tn_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -3075,6 +3226,7 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -3143,6 +3295,17 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(l2_tn_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct ixgbe_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = ixgbe_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -3194,6 +3357,8 @@ ixgbe_flow_flush(struct rte_eth_dev *dev,
 		return ret;
 	}
 
+	ixgbe_clear_rss_filter(dev);
+
 	ixgbe_filterlist_flush();
 
 	return 0;
diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index 9bc8462..4b38247 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -5550,6 +5550,71 @@ ixgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
 	}
 }
 
+int
+ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add)
+{
+	struct ixgbe_hw *hw;
+	uint32_t reta;
+	uint16_t i;
+	uint16_t j;
+	uint16_t sp_reta_size;
+	uint32_t reta_reg;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	PMD_INIT_FUNC_TRACE();
+	hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct ixgbe_rte_flow_rss_conf)) == 0) {
+			ixgbe_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+	/* Fill in redirection table
+	 * The byte-swap is needed because NIC registers are in
+	 * little-endian order.
+	 */
+	reta = 0;
+	for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
+		reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
+
+		if (j == conf->num)
+			j = 0;
+		reta = (reta << 8) | conf->queue[j];
+		if ((i & 3) == 3)
+			IXGBE_WRITE_REG(hw, reta_reg,
+					rte_bswap32(reta));
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
+		ixgbe_rss_disable(dev);
+		return -EINVAL;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	ixgbe_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct ixgbe_rte_flow_rss_conf));
+
+	return 0;
+}
+
 /* Stubs needed for linkage when CONFIG_RTE_IXGBE_INC_VECTOR is set to 'n' */
 int __attribute__((weak))
 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v3 0/2] move RSS to flow API
  2017-11-24  3:10 ` [PATCH v2 0/2] " Wei Zhao
  2017-11-24  3:10   ` [PATCH v2 1/2] net/e1000: " Wei Zhao
  2017-11-24  3:10   ` [PATCH v2 2/2] net/ixgbe: " Wei Zhao
@ 2017-11-24  8:05   ` Wei Zhao
  2017-11-24  8:05     ` [PATCH v3 1/2] net/e1000: " Wei Zhao
                       ` (2 more replies)
  2 siblings, 3 replies; 28+ messages in thread
From: Wei Zhao @ 2017-11-24  8:05 UTC (permalink / raw)
  To: dev

The patches mainly finish following functions:
1) igb move RSS to flow API
2) ixgbe move RSS to flow API

v2:
-fix bug for RSS flush code.
-fix patch check warning.

v3:
-fix bug for ixgbe rss restore.

root (2):
  net/e1000: move RSS to flow API
  net/ixgbe: move RSS to flow API

 drivers/net/e1000/e1000_ethdev.h |  20 +++++
 drivers/net/e1000/igb_ethdev.c   |  17 ++++
 drivers/net/e1000/igb_flow.c     | 160 +++++++++++++++++++++++++++++++++++++
 drivers/net/e1000/igb_rxtx.c     |  61 +++++++++++++++
 drivers/net/ixgbe/ixgbe_ethdev.c |  13 +++
 drivers/net/ixgbe/ixgbe_ethdev.h |  10 +++
 drivers/net/ixgbe/ixgbe_flow.c   | 165 +++++++++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_rxtx.c   |  65 +++++++++++++++
 8 files changed, 511 insertions(+)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v3 1/2] net/e1000: move RSS to flow API
  2017-11-24  8:05   ` [PATCH v3 0/2] " Wei Zhao
@ 2017-11-24  8:05     ` Wei Zhao
  2017-12-07  9:19       ` Dai, Wei
  2017-11-24  8:05     ` [PATCH v3 2/2] net/ixgbe: " Wei Zhao
  2018-01-04  7:46     ` [PATCH v4 0/2] " Wei Zhao
  2 siblings, 1 reply; 28+ messages in thread
From: Wei Zhao @ 2017-11-24  8:05 UTC (permalink / raw)
  To: dev; +Cc: Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move igb existing RSS to rte_flow.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
---
 drivers/net/e1000/e1000_ethdev.h |  20 +++++
 drivers/net/e1000/igb_ethdev.c   |  17 +++++
 drivers/net/e1000/igb_flow.c     | 160 +++++++++++++++++++++++++++++++++++++++
 drivers/net/e1000/igb_rxtx.c     |  61 +++++++++++++++
 4 files changed, 258 insertions(+)

diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index 5668910..0731766 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -257,6 +257,12 @@ struct igb_ethertype_filter {
 	uint32_t etqf;
 };
 
+struct igb_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IGB_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /*
  * Structure to store filters'info.
  */
@@ -274,6 +280,8 @@ struct e1000_filter_info {
 	struct e1000_2tuple_filter_list twotuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct igb_rte_flow_rss_conf rss_info;
 };
 
 /*
@@ -342,6 +350,12 @@ struct igb_flex_filter_ele {
 	struct rte_eth_flex_filter filter_info;
 };
 
+/* rss filter  list structure */
+struct igb_rss_conf_ele {
+	TAILQ_ENTRY(igb_rss_conf_ele) entries;
+	struct igb_rte_flow_rss_conf filter_info;
+};
+
 /* igb_flow memory list structure */
 struct igb_flow_mem {
 	TAILQ_ENTRY(igb_flow_mem) entries;
@@ -357,6 +371,8 @@ TAILQ_HEAD(igb_syn_filter_list, igb_eth_syn_filter_ele);
 struct igb_syn_filter_list igb_filter_syn_list;
 TAILQ_HEAD(igb_flex_filter_list, igb_flex_filter_ele);
 struct igb_flex_filter_list igb_filter_flex_list;
+TAILQ_HEAD(igb_rss_filter_list, igb_rss_conf_ele);
+struct igb_rss_filter_list igb_filter_rss_list;
 TAILQ_HEAD(igb_flow_mem_list, igb_flow_mem);
 struct igb_flow_mem_list igb_flow_list;
 
@@ -500,4 +516,8 @@ int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
 int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
 			struct rte_eth_flex_filter *filter,
 			bool add);
+int igb_config_rss_filter(struct rte_eth_dev *dev,
+			struct igb_rte_flow_rss_conf *conf,
+			bool add);
+
 #endif /* _E1000_ETHDEV_H_ */
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index fdc139f..275fa02 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -948,6 +948,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 	TAILQ_INIT(&igb_filter_ethertype_list);
 	TAILQ_INIT(&igb_filter_syn_list);
 	TAILQ_INIT(&igb_filter_flex_list);
+	TAILQ_INIT(&igb_filter_rss_list);
 	TAILQ_INIT(&igb_flow_list);
 
 	return 0;
@@ -1007,6 +1008,10 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 	memset(filter_info->ethertype_filters, 0,
 		E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
 
+	/* clear the rss filter info */
+	memset(&filter_info->rss_info, 0,
+		sizeof(struct igb_rte_flow_rss_conf));
+
 	/* remove all ntuple filters of the device */
 	igb_ntuple_filter_uninit(eth_dev);
 
@@ -5628,6 +5633,17 @@ igb_flex_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+igb_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		igb_config_rss_filter(dev, &filter_info->rss_info, TRUE);
+}
+
 /* restore all types filter */
 static int
 igb_filter_restore(struct rte_eth_dev *dev)
@@ -5636,6 +5652,7 @@ igb_filter_restore(struct rte_eth_dev *dev)
 	igb_ethertype_filter_restore(dev);
 	igb_syn_filter_restore(dev);
 	igb_flex_filter_restore(dev);
+	igb_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/e1000/igb_flow.c b/drivers/net/e1000/igb_flow.c
index 22bad26..bf5cfac 100644
--- a/drivers/net/e1000/igb_flow.c
+++ b/drivers/net/e1000/igb_flow.c
@@ -1295,6 +1295,101 @@ igb_parse_flex_filter(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+igb_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct igb_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n, index;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	index = 0;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	index++;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
 /**
  * Create a flow rule.
  * Theorically one rule can match more than one filters.
@@ -1313,11 +1408,13 @@ igb_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct igb_ntuple_filter_ele *ntuple_filter_ptr;
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 
 	flow = rte_zmalloc("igb_rte_flow", sizeof(struct rte_flow), 0);
@@ -1419,6 +1516,29 @@ igb_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = igb_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("igb_rss_filter",
+				sizeof(struct igb_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct igb_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&igb_flow_list,
 		igb_flow_mem_ptr, entries);
@@ -1446,6 +1566,7 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -1469,6 +1590,12 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	memset(&flex_filter, 0, sizeof(struct rte_eth_flex_filter));
 	ret = igb_parse_flex_filter(dev, attr, pattern,
 				actions, &flex_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -1487,6 +1614,7 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -1533,6 +1661,17 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(flex_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct igb_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = igb_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -1621,6 +1760,17 @@ igb_clear_all_flex_filter(struct rte_eth_dev *dev)
 		igb_remove_flex_filter(dev, flex_filter);
 }
 
+/* remove the rss filter */
+static void
+igb_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter->rss_info.num)
+		igb_config_rss_filter(dev, &filter->rss_info, FALSE);
+}
+
 void
 igb_filterlist_flush(struct rte_eth_dev *dev)
 {
@@ -1628,6 +1778,7 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele  *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 	enum rte_filter_type filter_type;
 	struct rte_flow *pmd_flow;
@@ -1670,6 +1821,14 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 						flex_filter_ptr, entries);
 				rte_free(flex_filter_ptr);
 				break;
+			case RTE_ETH_FILTER_HASH:
+				rss_filter_ptr =
+					(struct igb_rss_conf_ele *)
+						pmd_flow->rule;
+				TAILQ_REMOVE(&igb_filter_rss_list,
+						rss_filter_ptr, entries);
+				rte_free(rss_filter_ptr);
+				break;
 			default:
 				PMD_DRV_LOG(WARNING, "Filter type"
 					"(%d) not supported", filter_type);
@@ -1693,6 +1852,7 @@ igb_flow_flush(struct rte_eth_dev *dev,
 	igb_clear_all_ethertype_filter(dev);
 	igb_clear_syn_filter(dev);
 	igb_clear_all_flex_filter(dev);
+	igb_clear_rss_filter(dev);
 	igb_filterlist_flush(dev);
 
 	return 0;
diff --git a/drivers/net/e1000/igb_rxtx.c b/drivers/net/e1000/igb_rxtx.c
index 4ee12e9..af86726 100644
--- a/drivers/net/e1000/igb_rxtx.c
+++ b/drivers/net/e1000/igb_rxtx.c
@@ -2786,3 +2786,64 @@ igb_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 	qinfo->conf.tx_thresh.hthresh = txq->hthresh;
 	qinfo->conf.tx_thresh.wthresh = txq->wthresh;
 }
+
+int
+igb_config_rss_filter(struct rte_eth_dev *dev,
+		struct igb_rte_flow_rss_conf *conf, bool add)
+{
+	uint32_t shift;
+	uint16_t i, j;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct igb_rte_flow_rss_conf)) == 0) {
+			igb_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct igb_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+
+	/* Fill in redirection table. */
+	shift = (hw->mac.type == e1000_82575) ? 6 : 0;
+	for (i = 0, j = 0; i < 128; i++, j++) {
+		union e1000_reta {
+			uint32_t dword;
+			uint8_t  bytes[4];
+		} reta;
+		uint8_t q_idx;
+
+		q_idx = conf->queue[j];
+		if (j == conf->num)
+			j = 0;
+		reta.bytes[i & 3] = (uint8_t)(q_idx << shift);
+		if ((i & 3) == 3)
+			E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
+		igb_rss_disable(dev);
+		return 0;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	igb_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct igb_rte_flow_rss_conf));
+
+	return 0;
+}
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v3 2/2] net/ixgbe: move RSS to flow API
  2017-11-24  8:05   ` [PATCH v3 0/2] " Wei Zhao
  2017-11-24  8:05     ` [PATCH v3 1/2] net/e1000: " Wei Zhao
@ 2017-11-24  8:05     ` Wei Zhao
  2017-12-07  9:19       ` Dai, Wei
  2018-01-04  7:46     ` [PATCH v4 0/2] " Wei Zhao
  2 siblings, 1 reply; 28+ messages in thread
From: Wei Zhao @ 2017-11-24  8:05 UTC (permalink / raw)
  To: dev; +Cc: Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move ixgbe existing RSS to rte_flow.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
---
 drivers/net/ixgbe/ixgbe_ethdev.c |  13 +++
 drivers/net/ixgbe/ixgbe_ethdev.h |  10 +++
 drivers/net/ixgbe/ixgbe_flow.c   | 165 +++++++++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_rxtx.c   |  65 +++++++++++++++
 4 files changed, 253 insertions(+)

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index ff19a56..4960650 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -8339,6 +8339,18 @@ ixgbe_l2_tn_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+ixgbe_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		ixgbe_config_rss_filter(dev,
+			&filter_info->rss_info, TRUE);
+}
+
 static int
 ixgbe_filter_restore(struct rte_eth_dev *dev)
 {
@@ -8347,6 +8359,7 @@ ixgbe_filter_restore(struct rte_eth_dev *dev)
 	ixgbe_syn_filter_restore(dev);
 	ixgbe_fdir_filter_restore(dev);
 	ixgbe_l2_tn_filter_restore(dev);
+	ixgbe_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 51ddcfd..4af79b4 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -224,6 +224,12 @@ struct ixgbe_hw_fdir_info {
 	bool mask_added; /* If already got mask from consistent filter */
 };
 
+struct ixgbe_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IXGBE_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /* structure for interrupt relative data */
 struct ixgbe_interrupt {
 	uint32_t flags;
@@ -340,6 +346,8 @@ struct ixgbe_filter_info {
 	struct ixgbe_5tuple_filter_list fivetuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct ixgbe_rte_flow_rss_conf rss_info;
 };
 
 struct ixgbe_l2_tn_key {
@@ -719,6 +727,8 @@ void ixgbe_tm_conf_init(struct rte_eth_dev *dev);
 void ixgbe_tm_conf_uninit(struct rte_eth_dev *dev);
 int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev, uint16_t queue_idx,
 			       uint16_t tx_rate);
+int ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add);
 
 static inline int
 ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info,
diff --git a/drivers/net/ixgbe/ixgbe_flow.c b/drivers/net/ixgbe/ixgbe_flow.c
index 19c2d47..8f964cf 100644
--- a/drivers/net/ixgbe/ixgbe_flow.c
+++ b/drivers/net/ixgbe/ixgbe_flow.c
@@ -103,6 +103,11 @@ struct ixgbe_eth_l2_tunnel_conf_ele {
 	TAILQ_ENTRY(ixgbe_eth_l2_tunnel_conf_ele) entries;
 	struct rte_eth_l2_tunnel_conf filter_info;
 };
+/* rss filter list structure */
+struct ixgbe_rss_conf_ele {
+	TAILQ_ENTRY(ixgbe_rss_conf_ele) entries;
+	struct ixgbe_rte_flow_rss_conf filter_info;
+};
 /* ixgbe_flow memory list structure */
 struct ixgbe_flow_mem {
 	TAILQ_ENTRY(ixgbe_flow_mem) entries;
@@ -114,6 +119,7 @@ TAILQ_HEAD(ixgbe_ethertype_filter_list, ixgbe_ethertype_filter_ele);
 TAILQ_HEAD(ixgbe_syn_filter_list, ixgbe_eth_syn_filter_ele);
 TAILQ_HEAD(ixgbe_fdir_rule_filter_list, ixgbe_fdir_rule_ele);
 TAILQ_HEAD(ixgbe_l2_tunnel_filter_list, ixgbe_eth_l2_tunnel_conf_ele);
+TAILQ_HEAD(ixgbe_rss_filter_list, ixgbe_rss_conf_ele);
 TAILQ_HEAD(ixgbe_flow_mem_list, ixgbe_flow_mem);
 
 static struct ixgbe_ntuple_filter_list filter_ntuple_list;
@@ -121,6 +127,7 @@ static struct ixgbe_ethertype_filter_list filter_ethertype_list;
 static struct ixgbe_syn_filter_list filter_syn_list;
 static struct ixgbe_fdir_rule_filter_list filter_fdir_list;
 static struct ixgbe_l2_tunnel_filter_list filter_l2_tunnel_list;
+static struct ixgbe_rss_filter_list filter_rss_list;
 static struct ixgbe_flow_mem_list ixgbe_flow_list;
 
 /**
@@ -2700,6 +2707,109 @@ ixgbe_parse_fdir_filter(struct rte_eth_dev *dev,
 	return ret;
 }
 
+static int
+ixgbe_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct ixgbe_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	act = next_no_void_action(actions, NULL);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	act = next_no_void_action(actions, act);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
+/* remove the rss filter */
+static void
+ixgbe_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		ixgbe_config_rss_filter(dev, &filter_info->rss_info, FALSE);
+}
+
 void
 ixgbe_filterlist_init(void)
 {
@@ -2708,6 +2818,7 @@ ixgbe_filterlist_init(void)
 	TAILQ_INIT(&filter_syn_list);
 	TAILQ_INIT(&filter_fdir_list);
 	TAILQ_INIT(&filter_l2_tunnel_list);
+	TAILQ_INIT(&filter_rss_list);
 	TAILQ_INIT(&ixgbe_flow_list);
 }
 
@@ -2720,6 +2831,7 @@ ixgbe_filterlist_flush(void)
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	while ((ntuple_filter_ptr = TAILQ_FIRST(&filter_ntuple_list))) {
 		TAILQ_REMOVE(&filter_ntuple_list,
@@ -2756,6 +2868,13 @@ ixgbe_filterlist_flush(void)
 		rte_free(fdir_rule_ptr);
 	}
 
+	while ((rss_filter_ptr = TAILQ_FIRST(&filter_rss_list))) {
+		TAILQ_REMOVE(&filter_rss_list,
+				 rss_filter_ptr,
+				 entries);
+		rte_free(rss_filter_ptr);
+	}
+
 	while ((ixgbe_flow_mem_ptr = TAILQ_FIRST(&ixgbe_flow_list))) {
 		TAILQ_REMOVE(&ixgbe_flow_list,
 				 ixgbe_flow_mem_ptr,
@@ -2786,12 +2905,14 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct ixgbe_ntuple_filter_ele *ntuple_filter_ptr;
 	struct ixgbe_ethertype_filter_ele *ethertype_filter_ptr;
 	struct ixgbe_eth_syn_filter_ele *syn_filter_ptr;
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	uint8_t first_mask = FALSE;
 
@@ -2992,6 +3113,29 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = ixgbe_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("ixgbe_rss_filter",
+				sizeof(struct ixgbe_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&ixgbe_flow_list,
 		ixgbe_flow_mem_ptr, entries);
@@ -3020,6 +3164,7 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_fdir_rule fdir_rule;
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -3049,6 +3194,12 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	memset(&l2_tn_filter, 0, sizeof(struct rte_eth_l2_tunnel_conf));
 	ret = ixgbe_parse_l2_tn_filter(dev, attr, pattern,
 				actions, &l2_tn_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -3075,6 +3226,7 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -3143,6 +3295,17 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(l2_tn_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct ixgbe_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = ixgbe_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -3194,6 +3357,8 @@ ixgbe_flow_flush(struct rte_eth_dev *dev,
 		return ret;
 	}
 
+	ixgbe_clear_rss_filter(dev);
+
 	ixgbe_filterlist_flush();
 
 	return 0;
diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index 9bc8462..4b38247 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -5550,6 +5550,71 @@ ixgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
 	}
 }
 
+int
+ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add)
+{
+	struct ixgbe_hw *hw;
+	uint32_t reta;
+	uint16_t i;
+	uint16_t j;
+	uint16_t sp_reta_size;
+	uint32_t reta_reg;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	PMD_INIT_FUNC_TRACE();
+	hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct ixgbe_rte_flow_rss_conf)) == 0) {
+			ixgbe_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+	/* Fill in redirection table
+	 * The byte-swap is needed because NIC registers are in
+	 * little-endian order.
+	 */
+	reta = 0;
+	for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
+		reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
+
+		if (j == conf->num)
+			j = 0;
+		reta = (reta << 8) | conf->queue[j];
+		if ((i & 3) == 3)
+			IXGBE_WRITE_REG(hw, reta_reg,
+					rte_bswap32(reta));
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
+		ixgbe_rss_disable(dev);
+		return -EINVAL;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	ixgbe_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct ixgbe_rte_flow_rss_conf));
+
+	return 0;
+}
+
 /* Stubs needed for linkage when CONFIG_RTE_IXGBE_INC_VECTOR is set to 'n' */
 int __attribute__((weak))
 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH v3 1/2] net/e1000: move RSS to flow API
  2017-11-24  8:05     ` [PATCH v3 1/2] net/e1000: " Wei Zhao
@ 2017-12-07  9:19       ` Dai, Wei
  2017-12-08  2:28         ` Zhao1, Wei
  0 siblings, 1 reply; 28+ messages in thread
From: Dai, Wei @ 2017-12-07  9:19 UTC (permalink / raw)
  To: Zhao1, Wei, dev; +Cc: Zhao1, Wei

Hi, Zhao Wei
Please correct build error show in http://dpdk.org/ml/archives/test-report/2017-November/035129.html


> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Wei Zhao
> Sent: Friday, November 24, 2017 4:05 PM
> To: dev@dpdk.org
> Cc: Zhao1, Wei <wei.zhao1@intel.com>
> Subject: [dpdk-dev] [PATCH v3 1/2] net/e1000: move RSS to flow API
> 
> Rte_flow actually defined to include RSS, but till now, RSS is out of rte_flow.
> This patch is to move igb existing RSS to rte_flow.
> 
> Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
> ---
>  drivers/net/e1000/e1000_ethdev.h |  20 +++++
>  drivers/net/e1000/igb_ethdev.c   |  17 +++++
>  drivers/net/e1000/igb_flow.c     | 160
> +++++++++++++++++++++++++++++++++++++++
>  drivers/net/e1000/igb_rxtx.c     |  61 +++++++++++++++
>  4 files changed, 258 insertions(+)
> 
> diff --git a/drivers/net/e1000/e1000_ethdev.h
> b/drivers/net/e1000/e1000_ethdev.h
> index 5668910..0731766 100644
> --- a/drivers/net/e1000/e1000_ethdev.h
> +++ b/drivers/net/e1000/e1000_ethdev.h
> @@ -257,6 +257,12 @@ struct igb_ethertype_filter {
>  	uint32_t etqf;
>  };
> 
> +struct igb_rte_flow_rss_conf {
> +	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
> +	uint16_t num; /**< Number of entries in queue[]. */
> +	uint16_t queue[IGB_MAX_RX_QUEUE_NUM]; /**< Queues indices to
> use. */
> +};
> +
>  /*
>   * Structure to store filters'info.
>   */
> @@ -274,6 +280,8 @@ struct e1000_filter_info {
>  	struct e1000_2tuple_filter_list twotuple_list;
>  	/* store the SYN filter info */
>  	uint32_t syn_info;
> +	/* store the rss filter info */
> +	struct igb_rte_flow_rss_conf rss_info;
>  };
> 
>  /*
> @@ -342,6 +350,12 @@ struct igb_flex_filter_ele {
>  	struct rte_eth_flex_filter filter_info;  };
> 
> +/* rss filter  list structure */
> +struct igb_rss_conf_ele {
> +	TAILQ_ENTRY(igb_rss_conf_ele) entries;
> +	struct igb_rte_flow_rss_conf filter_info; };
> +
>  /* igb_flow memory list structure */
>  struct igb_flow_mem {
>  	TAILQ_ENTRY(igb_flow_mem) entries;
> @@ -357,6 +371,8 @@ TAILQ_HEAD(igb_syn_filter_list,
> igb_eth_syn_filter_ele);  struct igb_syn_filter_list igb_filter_syn_list;
> TAILQ_HEAD(igb_flex_filter_list, igb_flex_filter_ele);  struct
> igb_flex_filter_list igb_filter_flex_list;
> +TAILQ_HEAD(igb_rss_filter_list, igb_rss_conf_ele); struct
> +igb_rss_filter_list igb_filter_rss_list;
>  TAILQ_HEAD(igb_flow_mem_list, igb_flow_mem);  struct
> igb_flow_mem_list igb_flow_list;
> 
> @@ -500,4 +516,8 @@ int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
> int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
>  			struct rte_eth_flex_filter *filter,
>  			bool add);
> +int igb_config_rss_filter(struct rte_eth_dev *dev,
> +			struct igb_rte_flow_rss_conf *conf,
> +			bool add);
> +
>  #endif /* _E1000_ETHDEV_H_ */
> diff --git a/drivers/net/e1000/igb_ethdev.c
> b/drivers/net/e1000/igb_ethdev.c index fdc139f..275fa02 100644
> --- a/drivers/net/e1000/igb_ethdev.c
> +++ b/drivers/net/e1000/igb_ethdev.c
> @@ -948,6 +948,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
>  	TAILQ_INIT(&igb_filter_ethertype_list);
>  	TAILQ_INIT(&igb_filter_syn_list);
>  	TAILQ_INIT(&igb_filter_flex_list);
> +	TAILQ_INIT(&igb_filter_rss_list);
>  	TAILQ_INIT(&igb_flow_list);
> 
>  	return 0;
> @@ -1007,6 +1008,10 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
>  	memset(filter_info->ethertype_filters, 0,
>  		E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
> 
> +	/* clear the rss filter info */
> +	memset(&filter_info->rss_info, 0,
> +		sizeof(struct igb_rte_flow_rss_conf));
> +
>  	/* remove all ntuple filters of the device */
>  	igb_ntuple_filter_uninit(eth_dev);
> 
> @@ -5628,6 +5633,17 @@ igb_flex_filter_restore(struct rte_eth_dev *dev)
>  	}
>  }
> 
> +/* restore rss filter */
> +static inline void
> +igb_rss_filter_restore(struct rte_eth_dev *dev) {
> +	struct e1000_filter_info *filter_info =
> +		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
> +
> +	if (filter_info->rss_info.num)
> +		igb_config_rss_filter(dev, &filter_info->rss_info, TRUE); }
> +
>  /* restore all types filter */
>  static int
>  igb_filter_restore(struct rte_eth_dev *dev) @@ -5636,6 +5652,7 @@
> igb_filter_restore(struct rte_eth_dev *dev)
>  	igb_ethertype_filter_restore(dev);
>  	igb_syn_filter_restore(dev);
>  	igb_flex_filter_restore(dev);
> +	igb_rss_filter_restore(dev);
> 
>  	return 0;
>  }
> diff --git a/drivers/net/e1000/igb_flow.c b/drivers/net/e1000/igb_flow.c
> index 22bad26..bf5cfac 100644
> --- a/drivers/net/e1000/igb_flow.c
> +++ b/drivers/net/e1000/igb_flow.c
> @@ -1295,6 +1295,101 @@ igb_parse_flex_filter(struct rte_eth_dev *dev,
>  	return 0;
>  }
> 
> +static int
> +igb_parse_rss_filter(struct rte_eth_dev *dev,
> +			const struct rte_flow_attr *attr,
> +			const struct rte_flow_action actions[],
> +			struct igb_rte_flow_rss_conf *rss_conf,
> +			struct rte_flow_error *error)
> +{
> +	const struct rte_flow_action *act;
> +	const struct rte_flow_action_rss *rss;
> +	uint16_t n, index;
> +
> +	/**
> +	 * rss only supports forwarding,
> +	 * check if the first not void action is RSS.
> +	 */
> +	index = 0;
> +	NEXT_ITEM_OF_ACTION(act, actions, index);
> +	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
> +		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> +		rte_flow_error_set(error, EINVAL,
> +			RTE_FLOW_ERROR_TYPE_ACTION,
> +			act, "Not supported action.");
> +		return -rte_errno;
> +	}
> +
> +	rss = (const struct rte_flow_action_rss *)act->conf;
> +
> +	if (!rss || !rss->num) {
> +		rte_flow_error_set(error, EINVAL,
> +				RTE_FLOW_ERROR_TYPE_ACTION,
> +				act,
> +			   "no valid queues");
> +		return -rte_errno;
> +	}
> +
> +	for (n = 0; n < rss->num; n++) {
> +		if (rss->queue[n] >= dev->data->nb_rx_queues) {
> +			rte_flow_error_set(error, EINVAL,
> +				   RTE_FLOW_ERROR_TYPE_ACTION,
> +				   act,
> +				   "queue id > max number of queues");
> +			return -rte_errno;
> +		}
> +	}
> +
> +	if (rss->rss_conf)
> +		rss_conf->rss_conf = *rss->rss_conf;
> +	else
> +		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
> +
> +	for (n = 0; n < rss->num; ++n)
> +		rss_conf->queue[n] = rss->queue[n];
> +	rss_conf->num = rss->num;
> +
> +	/* check if the next not void item is END */
> +	index++;
> +	NEXT_ITEM_OF_ACTION(act, actions, index);
> +	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
> +		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
> +		rte_flow_error_set(error, EINVAL,
> +			RTE_FLOW_ERROR_TYPE_ACTION,
> +			act, "Not supported action.");
> +		return -rte_errno;
> +	}
> +
> +	/* parse attr */
> +	/* must be input direction */
> +	if (!attr->ingress) {
> +		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> +		rte_flow_error_set(error, EINVAL,
> +				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
> +				   attr, "Only support ingress.");
> +		return -rte_errno;
> +	}
> +
> +	/* not supported */
> +	if (attr->egress) {
> +		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> +		rte_flow_error_set(error, EINVAL,
> +				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
> +				   attr, "Not support egress.");
> +		return -rte_errno;
> +	}
> +
> +	if (attr->priority > 0xFFFF) {
> +		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> +		rte_flow_error_set(error, EINVAL,
> +				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
> +				   attr, "Error priority.");
> +		return -rte_errno;
> +	}
> +
> +	return 0;
> +}
> +
>  /**
>   * Create a flow rule.
>   * Theorically one rule can match more than one filters.
> @@ -1313,11 +1408,13 @@ igb_flow_create(struct rte_eth_dev *dev,
>  	struct rte_eth_ethertype_filter ethertype_filter;
>  	struct rte_eth_syn_filter syn_filter;
>  	struct rte_eth_flex_filter flex_filter;
> +	struct igb_rte_flow_rss_conf rss_conf;
>  	struct rte_flow *flow = NULL;
>  	struct igb_ntuple_filter_ele *ntuple_filter_ptr;
>  	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
>  	struct igb_eth_syn_filter_ele *syn_filter_ptr;
>  	struct igb_flex_filter_ele *flex_filter_ptr;
> +	struct igb_rss_conf_ele *rss_filter_ptr;
>  	struct igb_flow_mem *igb_flow_mem_ptr;
> 
>  	flow = rte_zmalloc("igb_rte_flow", sizeof(struct rte_flow), 0); @@
> -1419,6 +1516,29 @@ igb_flow_create(struct rte_eth_dev *dev,
>  		}
>  	}
> 
> +	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> +	ret = igb_parse_rss_filter(dev, attr,
> +					actions, &rss_conf, error);
> +	if (!ret) {
> +		ret = igb_config_rss_filter(dev, &rss_conf, TRUE);
> +		if (!ret) {
> +			rss_filter_ptr = rte_zmalloc("igb_rss_filter",
> +				sizeof(struct igb_rss_conf_ele), 0);
> +			if (!rss_filter_ptr) {
> +				PMD_DRV_LOG(ERR, "failed to allocate memory");
> +				goto out;
> +			}
> +			rte_memcpy(&rss_filter_ptr->filter_info,
> +				&rss_conf,
> +				sizeof(struct igb_rte_flow_rss_conf));
> +			TAILQ_INSERT_TAIL(&igb_filter_rss_list,
> +				rss_filter_ptr, entries);
> +			flow->rule = rss_filter_ptr;
> +			flow->filter_type = RTE_ETH_FILTER_HASH;
> +			return flow;
> +		}
> +	}
> +
>  out:
>  	TAILQ_REMOVE(&igb_flow_list,
>  		igb_flow_mem_ptr, entries);
> @@ -1446,6 +1566,7 @@ igb_flow_validate(__rte_unused struct
> rte_eth_dev *dev,
>  	struct rte_eth_ethertype_filter ethertype_filter;
>  	struct rte_eth_syn_filter syn_filter;
>  	struct rte_eth_flex_filter flex_filter;
> +	struct igb_rte_flow_rss_conf rss_conf;
>  	int ret;
> 
>  	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter)); @@
> -1469,6 +1590,12 @@ igb_flow_validate(__rte_unused struct rte_eth_dev
> *dev,
>  	memset(&flex_filter, 0, sizeof(struct rte_eth_flex_filter));
>  	ret = igb_parse_flex_filter(dev, attr, pattern,
>  				actions, &flex_filter, error);
> +	if (!ret)
> +		return 0;
> +
> +	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> +	ret = igb_parse_rss_filter(dev, attr,
> +					actions, &rss_conf, error);
> 
>  	return ret;
>  }
> @@ -1487,6 +1614,7 @@ igb_flow_destroy(struct rte_eth_dev *dev,
>  	struct igb_eth_syn_filter_ele *syn_filter_ptr;
>  	struct igb_flex_filter_ele *flex_filter_ptr;
>  	struct igb_flow_mem *igb_flow_mem_ptr;
> +	struct igb_rss_conf_ele *rss_filter_ptr;
> 
>  	switch (filter_type) {
>  	case RTE_ETH_FILTER_NTUPLE:
> @@ -1533,6 +1661,17 @@ igb_flow_destroy(struct rte_eth_dev *dev,
>  			rte_free(flex_filter_ptr);
>  		}
>  		break;
> +	case RTE_ETH_FILTER_HASH:
> +		rss_filter_ptr = (struct igb_rss_conf_ele *)
> +				pmd_flow->rule;
> +		ret = igb_config_rss_filter(dev,
> +					&rss_filter_ptr->filter_info, FALSE);
> +		if (!ret) {
> +			TAILQ_REMOVE(&igb_filter_rss_list,
> +				rss_filter_ptr, entries);
> +			rte_free(rss_filter_ptr);
> +		}
> +		break;
>  	default:
>  		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
>  			    filter_type);
> @@ -1621,6 +1760,17 @@ igb_clear_all_flex_filter(struct rte_eth_dev *dev)
>  		igb_remove_flex_filter(dev, flex_filter);  }
> 
> +/* remove the rss filter */
> +static void
> +igb_clear_rss_filter(struct rte_eth_dev *dev) {
> +	struct e1000_filter_info *filter =
> +		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
> +
> +	if (filter->rss_info.num)
> +		igb_config_rss_filter(dev, &filter->rss_info, FALSE); }
> +
>  void
>  igb_filterlist_flush(struct rte_eth_dev *dev)  { @@ -1628,6 +1778,7 @@
> igb_filterlist_flush(struct rte_eth_dev *dev)
>  	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
>  	struct igb_eth_syn_filter_ele *syn_filter_ptr;
>  	struct igb_flex_filter_ele *flex_filter_ptr;
> +	struct igb_rss_conf_ele  *rss_filter_ptr;
>  	struct igb_flow_mem *igb_flow_mem_ptr;
>  	enum rte_filter_type filter_type;
>  	struct rte_flow *pmd_flow;
> @@ -1670,6 +1821,14 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
>  						flex_filter_ptr, entries);
>  				rte_free(flex_filter_ptr);
>  				break;
> +			case RTE_ETH_FILTER_HASH:
> +				rss_filter_ptr =
> +					(struct igb_rss_conf_ele *)
> +						pmd_flow->rule;
> +				TAILQ_REMOVE(&igb_filter_rss_list,
> +						rss_filter_ptr, entries);
> +				rte_free(rss_filter_ptr);
> +				break;
>  			default:
>  				PMD_DRV_LOG(WARNING, "Filter type"
>  					"(%d) not supported", filter_type); @@ -1693,6
> +1852,7 @@ igb_flow_flush(struct rte_eth_dev *dev,
>  	igb_clear_all_ethertype_filter(dev);
>  	igb_clear_syn_filter(dev);
>  	igb_clear_all_flex_filter(dev);
> +	igb_clear_rss_filter(dev);
>  	igb_filterlist_flush(dev);
> 
>  	return 0;
> diff --git a/drivers/net/e1000/igb_rxtx.c b/drivers/net/e1000/igb_rxtx.c
> index 4ee12e9..af86726 100644
> --- a/drivers/net/e1000/igb_rxtx.c
> +++ b/drivers/net/e1000/igb_rxtx.c
> @@ -2786,3 +2786,64 @@ igb_txq_info_get(struct rte_eth_dev *dev,
> uint16_t queue_id,
>  	qinfo->conf.tx_thresh.hthresh = txq->hthresh;
>  	qinfo->conf.tx_thresh.wthresh = txq->wthresh;  }
> +
> +int
> +igb_config_rss_filter(struct rte_eth_dev *dev,
> +		struct igb_rte_flow_rss_conf *conf, bool add) {
> +	uint32_t shift;
> +	uint16_t i, j;
> +	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
> +	struct e1000_filter_info *filter_info =
> +		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
> +	struct e1000_hw *hw =
> E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> +
> +	hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> +
> +	if (!add) {
> +		if (memcmp(conf, &filter_info->rss_info,
> +			sizeof(struct igb_rte_flow_rss_conf)) == 0) {
> +			igb_rss_disable(dev);
> +			memset(&filter_info->rss_info, 0,
> +				sizeof(struct igb_rte_flow_rss_conf));
> +			return 0;
> +		}
> +		return -EINVAL;
> +	}
> +
> +	if (filter_info->rss_info.num)
> +		return -EINVAL;
> +
> +	/* Fill in redirection table. */
> +	shift = (hw->mac.type == e1000_82575) ? 6 : 0;
> +	for (i = 0, j = 0; i < 128; i++, j++) {
> +		union e1000_reta {
> +			uint32_t dword;
> +			uint8_t  bytes[4];
> +		} reta;
> +		uint8_t q_idx;
> +
> +		q_idx = conf->queue[j];
> +		if (j == conf->num)
> +			j = 0;
> +		reta.bytes[i & 3] = (uint8_t)(q_idx << shift);
> +		if ((i & 3) == 3)
> +			E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
> +	}
> +
> +	/* Configure the RSS key and the RSS protocols used to compute
> +	 * the RSS hash of input packets.
> +	 */
> +	if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
> +		igb_rss_disable(dev);
> +		return 0;
> +	}
> +	if (rss_conf.rss_key == NULL)
> +		rss_conf.rss_key = rss_intel_key; /* Default hash key */
> +	igb_hw_rss_hash_set(hw, &rss_conf);
> +
> +	rte_memcpy(&filter_info->rss_info,
> +		conf, sizeof(struct igb_rte_flow_rss_conf));
> +
> +	return 0;
> +}
> --
> 2.9.3

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v3 2/2] net/ixgbe: move RSS to flow API
  2017-11-24  8:05     ` [PATCH v3 2/2] net/ixgbe: " Wei Zhao
@ 2017-12-07  9:19       ` Dai, Wei
  2017-12-08  2:27         ` Zhao1, Wei
  0 siblings, 1 reply; 28+ messages in thread
From: Dai, Wei @ 2017-12-07  9:19 UTC (permalink / raw)
  To: Zhao1, Wei, dev; +Cc: Zhao1, Wei

Hi, Zhao Wei
Please correct build error show in http://dpdk.org/ml/archives/test-report/2017-November/035130.html

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Wei Zhao
> Sent: Friday, November 24, 2017 4:05 PM
> To: dev@dpdk.org
> Cc: Zhao1, Wei <wei.zhao1@intel.com>
> Subject: [dpdk-dev] [PATCH v3 2/2] net/ixgbe: move RSS to flow API
> 
> Rte_flow actually defined to include RSS, but till now, RSS is out of rte_flow.
> This patch is to move ixgbe existing RSS to rte_flow.
> 
> Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
> ---
>  drivers/net/ixgbe/ixgbe_ethdev.c |  13 +++
> drivers/net/ixgbe/ixgbe_ethdev.h |  10 +++
>  drivers/net/ixgbe/ixgbe_flow.c   | 165
> +++++++++++++++++++++++++++++++++++++++
>  drivers/net/ixgbe/ixgbe_rxtx.c   |  65 +++++++++++++++
>  4 files changed, 253 insertions(+)
> 
> diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c
> b/drivers/net/ixgbe/ixgbe_ethdev.c
> index ff19a56..4960650 100644
> --- a/drivers/net/ixgbe/ixgbe_ethdev.c
> +++ b/drivers/net/ixgbe/ixgbe_ethdev.c
> @@ -8339,6 +8339,18 @@ ixgbe_l2_tn_filter_restore(struct rte_eth_dev
> *dev)
>  	}
>  }
> 
> +/* restore rss filter */
> +static inline void
> +ixgbe_rss_filter_restore(struct rte_eth_dev *dev) {
> +	struct ixgbe_filter_info *filter_info =
> +		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
> +
> +	if (filter_info->rss_info.num)
> +		ixgbe_config_rss_filter(dev,
> +			&filter_info->rss_info, TRUE);
> +}
> +
>  static int
>  ixgbe_filter_restore(struct rte_eth_dev *dev)  { @@ -8347,6 +8359,7 @@
> ixgbe_filter_restore(struct rte_eth_dev *dev)
>  	ixgbe_syn_filter_restore(dev);
>  	ixgbe_fdir_filter_restore(dev);
>  	ixgbe_l2_tn_filter_restore(dev);
> +	ixgbe_rss_filter_restore(dev);
> 
>  	return 0;
>  }
> diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h
> b/drivers/net/ixgbe/ixgbe_ethdev.h
> index 51ddcfd..4af79b4 100644
> --- a/drivers/net/ixgbe/ixgbe_ethdev.h
> +++ b/drivers/net/ixgbe/ixgbe_ethdev.h
> @@ -224,6 +224,12 @@ struct ixgbe_hw_fdir_info {
>  	bool mask_added; /* If already got mask from consistent filter */  };
> 
> +struct ixgbe_rte_flow_rss_conf {
> +	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
> +	uint16_t num; /**< Number of entries in queue[]. */
> +	uint16_t queue[IXGBE_MAX_RX_QUEUE_NUM]; /**< Queues indices to
> use. */
> +};
> +
>  /* structure for interrupt relative data */  struct ixgbe_interrupt {
>  	uint32_t flags;
> @@ -340,6 +346,8 @@ struct ixgbe_filter_info {
>  	struct ixgbe_5tuple_filter_list fivetuple_list;
>  	/* store the SYN filter info */
>  	uint32_t syn_info;
> +	/* store the rss filter info */
> +	struct ixgbe_rte_flow_rss_conf rss_info;
>  };
> 
>  struct ixgbe_l2_tn_key {
> @@ -719,6 +727,8 @@ void ixgbe_tm_conf_init(struct rte_eth_dev *dev);
> void ixgbe_tm_conf_uninit(struct rte_eth_dev *dev);  int
> ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev, uint16_t queue_idx,
>  			       uint16_t tx_rate);
> +int ixgbe_config_rss_filter(struct rte_eth_dev *dev,
> +		struct ixgbe_rte_flow_rss_conf *conf, bool add);
> 
>  static inline int
>  ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info, diff --git
> a/drivers/net/ixgbe/ixgbe_flow.c b/drivers/net/ixgbe/ixgbe_flow.c index
> 19c2d47..8f964cf 100644
> --- a/drivers/net/ixgbe/ixgbe_flow.c
> +++ b/drivers/net/ixgbe/ixgbe_flow.c
> @@ -103,6 +103,11 @@ struct ixgbe_eth_l2_tunnel_conf_ele {
>  	TAILQ_ENTRY(ixgbe_eth_l2_tunnel_conf_ele) entries;
>  	struct rte_eth_l2_tunnel_conf filter_info;  };
> +/* rss filter list structure */
> +struct ixgbe_rss_conf_ele {
> +	TAILQ_ENTRY(ixgbe_rss_conf_ele) entries;
> +	struct ixgbe_rte_flow_rss_conf filter_info; };
>  /* ixgbe_flow memory list structure */
>  struct ixgbe_flow_mem {
>  	TAILQ_ENTRY(ixgbe_flow_mem) entries;
> @@ -114,6 +119,7 @@ TAILQ_HEAD(ixgbe_ethertype_filter_list,
> ixgbe_ethertype_filter_ele);  TAILQ_HEAD(ixgbe_syn_filter_list,
> ixgbe_eth_syn_filter_ele);  TAILQ_HEAD(ixgbe_fdir_rule_filter_list,
> ixgbe_fdir_rule_ele);  TAILQ_HEAD(ixgbe_l2_tunnel_filter_list,
> ixgbe_eth_l2_tunnel_conf_ele);
> +TAILQ_HEAD(ixgbe_rss_filter_list, ixgbe_rss_conf_ele);
>  TAILQ_HEAD(ixgbe_flow_mem_list, ixgbe_flow_mem);
> 
>  static struct ixgbe_ntuple_filter_list filter_ntuple_list; @@ -121,6 +127,7
> @@ static struct ixgbe_ethertype_filter_list filter_ethertype_list;  static
> struct ixgbe_syn_filter_list filter_syn_list;  static struct
> ixgbe_fdir_rule_filter_list filter_fdir_list;  static struct
> ixgbe_l2_tunnel_filter_list filter_l2_tunnel_list;
> +static struct ixgbe_rss_filter_list filter_rss_list;
>  static struct ixgbe_flow_mem_list ixgbe_flow_list;
> 
>  /**
> @@ -2700,6 +2707,109 @@ ixgbe_parse_fdir_filter(struct rte_eth_dev
> *dev,
>  	return ret;
>  }
> 
> +static int
> +ixgbe_parse_rss_filter(struct rte_eth_dev *dev,
> +			const struct rte_flow_attr *attr,
> +			const struct rte_flow_action actions[],
> +			struct ixgbe_rte_flow_rss_conf *rss_conf,
> +			struct rte_flow_error *error)
> +{
> +	const struct rte_flow_action *act;
> +	const struct rte_flow_action_rss *rss;
> +	uint16_t n;
> +
> +	/**
> +	 * rss only supports forwarding,
> +	 * check if the first not void action is RSS.
> +	 */
> +	act = next_no_void_action(actions, NULL);
> +	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
> +		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> +		rte_flow_error_set(error, EINVAL,
> +			RTE_FLOW_ERROR_TYPE_ACTION,
> +			act, "Not supported action.");
> +		return -rte_errno;
> +	}
> +
> +	rss = (const struct rte_flow_action_rss *)act->conf;
> +
> +	if (!rss || !rss->num) {
> +		rte_flow_error_set(error, EINVAL,
> +				RTE_FLOW_ERROR_TYPE_ACTION,
> +				act,
> +			   "no valid queues");
> +		return -rte_errno;
> +	}
> +
> +	for (n = 0; n < rss->num; n++) {
> +		if (rss->queue[n] >= dev->data->nb_rx_queues) {
> +			rte_flow_error_set(error, EINVAL,
> +				   RTE_FLOW_ERROR_TYPE_ACTION,
> +				   act,
> +				   "queue id > max number of queues");
> +			return -rte_errno;
> +		}
> +	}
> +	if (rss->rss_conf)
> +		rss_conf->rss_conf = *rss->rss_conf;
> +	else
> +		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
> +
> +	for (n = 0; n < rss->num; ++n)
> +		rss_conf->queue[n] = rss->queue[n];
> +	rss_conf->num = rss->num;
> +
> +	/* check if the next not void item is END */
> +	act = next_no_void_action(actions, act);
> +	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
> +		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
> +		rte_flow_error_set(error, EINVAL,
> +			RTE_FLOW_ERROR_TYPE_ACTION,
> +			act, "Not supported action.");
> +		return -rte_errno;
> +	}
> +
> +	/* parse attr */
> +	/* must be input direction */
> +	if (!attr->ingress) {
> +		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> +		rte_flow_error_set(error, EINVAL,
> +				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
> +				   attr, "Only support ingress.");
> +		return -rte_errno;
> +	}
> +
> +	/* not supported */
> +	if (attr->egress) {
> +		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> +		rte_flow_error_set(error, EINVAL,
> +				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
> +				   attr, "Not support egress.");
> +		return -rte_errno;
> +	}
> +
> +	if (attr->priority > 0xFFFF) {
> +		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> +		rte_flow_error_set(error, EINVAL,
> +				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
> +				   attr, "Error priority.");
> +		return -rte_errno;
> +	}
> +
> +	return 0;
> +}
> +
> +/* remove the rss filter */
> +static void
> +ixgbe_clear_rss_filter(struct rte_eth_dev *dev) {
> +	struct ixgbe_filter_info *filter_info =
> +		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
> +
> +	if (filter_info->rss_info.num)
> +		ixgbe_config_rss_filter(dev, &filter_info->rss_info, FALSE); }
> +
>  void
>  ixgbe_filterlist_init(void)
>  {
> @@ -2708,6 +2818,7 @@ ixgbe_filterlist_init(void)
>  	TAILQ_INIT(&filter_syn_list);
>  	TAILQ_INIT(&filter_fdir_list);
>  	TAILQ_INIT(&filter_l2_tunnel_list);
> +	TAILQ_INIT(&filter_rss_list);
>  	TAILQ_INIT(&ixgbe_flow_list);
>  }
> 
> @@ -2720,6 +2831,7 @@ ixgbe_filterlist_flush(void)
>  	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
>  	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
>  	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
> +	struct ixgbe_rss_conf_ele *rss_filter_ptr;
> 
>  	while ((ntuple_filter_ptr = TAILQ_FIRST(&filter_ntuple_list))) {
>  		TAILQ_REMOVE(&filter_ntuple_list,
> @@ -2756,6 +2868,13 @@ ixgbe_filterlist_flush(void)
>  		rte_free(fdir_rule_ptr);
>  	}
> 
> +	while ((rss_filter_ptr = TAILQ_FIRST(&filter_rss_list))) {
> +		TAILQ_REMOVE(&filter_rss_list,
> +				 rss_filter_ptr,
> +				 entries);
> +		rte_free(rss_filter_ptr);
> +	}
> +
>  	while ((ixgbe_flow_mem_ptr = TAILQ_FIRST(&ixgbe_flow_list))) {
>  		TAILQ_REMOVE(&ixgbe_flow_list,
>  				 ixgbe_flow_mem_ptr,
> @@ -2786,12 +2905,14 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
>  	struct rte_eth_l2_tunnel_conf l2_tn_filter;
>  	struct ixgbe_hw_fdir_info *fdir_info =
>  		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
> +	struct ixgbe_rte_flow_rss_conf rss_conf;
>  	struct rte_flow *flow = NULL;
>  	struct ixgbe_ntuple_filter_ele *ntuple_filter_ptr;
>  	struct ixgbe_ethertype_filter_ele *ethertype_filter_ptr;
>  	struct ixgbe_eth_syn_filter_ele *syn_filter_ptr;
>  	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
>  	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
> +	struct ixgbe_rss_conf_ele *rss_filter_ptr;
>  	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
>  	uint8_t first_mask = FALSE;
> 
> @@ -2992,6 +3113,29 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
>  		}
>  	}
> 
> +	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> +	ret = ixgbe_parse_rss_filter(dev, attr,
> +					actions, &rss_conf, error);
> +	if (!ret) {
> +		ret = ixgbe_config_rss_filter(dev, &rss_conf, TRUE);
> +		if (!ret) {
> +			rss_filter_ptr = rte_zmalloc("ixgbe_rss_filter",
> +				sizeof(struct ixgbe_rss_conf_ele), 0);
> +			if (!rss_filter_ptr) {
> +				PMD_DRV_LOG(ERR, "failed to allocate memory");
> +				goto out;
> +			}
> +			rte_memcpy(&rss_filter_ptr->filter_info,
> +				&rss_conf,
> +				sizeof(struct ixgbe_rte_flow_rss_conf));
> +			TAILQ_INSERT_TAIL(&filter_rss_list,
> +				rss_filter_ptr, entries);
> +			flow->rule = rss_filter_ptr;
> +			flow->filter_type = RTE_ETH_FILTER_HASH;
> +			return flow;
> +		}
> +	}
> +
>  out:
>  	TAILQ_REMOVE(&ixgbe_flow_list,
>  		ixgbe_flow_mem_ptr, entries);
> @@ -3020,6 +3164,7 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
>  	struct rte_eth_syn_filter syn_filter;
>  	struct rte_eth_l2_tunnel_conf l2_tn_filter;
>  	struct ixgbe_fdir_rule fdir_rule;
> +	struct ixgbe_rte_flow_rss_conf rss_conf;
>  	int ret;
> 
>  	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter)); @@
> -3049,6 +3194,12 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
>  	memset(&l2_tn_filter, 0, sizeof(struct rte_eth_l2_tunnel_conf));
>  	ret = ixgbe_parse_l2_tn_filter(dev, attr, pattern,
>  				actions, &l2_tn_filter, error);
> +	if (!ret)
> +		return 0;
> +
> +	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> +	ret = ixgbe_parse_rss_filter(dev, attr,
> +					actions, &rss_conf, error);
> 
>  	return ret;
>  }
> @@ -3075,6 +3226,7 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
>  	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
>  	struct ixgbe_hw_fdir_info *fdir_info =
>  		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
> +	struct ixgbe_rss_conf_ele *rss_filter_ptr;
> 
>  	switch (filter_type) {
>  	case RTE_ETH_FILTER_NTUPLE:
> @@ -3143,6 +3295,17 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
>  			rte_free(l2_tn_filter_ptr);
>  		}
>  		break;
> +	case RTE_ETH_FILTER_HASH:
> +		rss_filter_ptr = (struct ixgbe_rss_conf_ele *)
> +				pmd_flow->rule;
> +		ret = ixgbe_config_rss_filter(dev,
> +					&rss_filter_ptr->filter_info, FALSE);
> +		if (!ret) {
> +			TAILQ_REMOVE(&filter_rss_list,
> +				rss_filter_ptr, entries);
> +			rte_free(rss_filter_ptr);
> +		}
> +		break;
>  	default:
>  		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
>  			    filter_type);
> @@ -3194,6 +3357,8 @@ ixgbe_flow_flush(struct rte_eth_dev *dev,
>  		return ret;
>  	}
> 
> +	ixgbe_clear_rss_filter(dev);
> +
>  	ixgbe_filterlist_flush();
> 
>  	return 0;
> diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
> index 9bc8462..4b38247 100644
> --- a/drivers/net/ixgbe/ixgbe_rxtx.c
> +++ b/drivers/net/ixgbe/ixgbe_rxtx.c
> @@ -5550,6 +5550,71 @@ ixgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
>  	}
>  }
> 
> +int
> +ixgbe_config_rss_filter(struct rte_eth_dev *dev,
> +		struct ixgbe_rte_flow_rss_conf *conf, bool add) {
> +	struct ixgbe_hw *hw;
> +	uint32_t reta;
> +	uint16_t i;
> +	uint16_t j;
> +	uint16_t sp_reta_size;
> +	uint32_t reta_reg;
> +	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
> +	struct ixgbe_filter_info *filter_info =
> +		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
> +
> +	PMD_INIT_FUNC_TRACE();
> +	hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> +
> +	sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
> +
> +	if (!add) {
> +		if (memcmp(conf, &filter_info->rss_info,
> +			sizeof(struct ixgbe_rte_flow_rss_conf)) == 0) {
> +			ixgbe_rss_disable(dev);
> +			memset(&filter_info->rss_info, 0,
> +				sizeof(struct ixgbe_rte_flow_rss_conf));
> +			return 0;
> +		}
> +		return -EINVAL;
> +	}
> +
> +	if (filter_info->rss_info.num)
> +		return -EINVAL;
> +	/* Fill in redirection table
> +	 * The byte-swap is needed because NIC registers are in
> +	 * little-endian order.
> +	 */
> +	reta = 0;
> +	for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
> +		reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
> +
> +		if (j == conf->num)
> +			j = 0;
> +		reta = (reta << 8) | conf->queue[j];
> +		if ((i & 3) == 3)
> +			IXGBE_WRITE_REG(hw, reta_reg,
> +					rte_bswap32(reta));
> +	}
> +
> +	/* Configure the RSS key and the RSS protocols used to compute
> +	 * the RSS hash of input packets.
> +	 */
> +	if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
> +		ixgbe_rss_disable(dev);
> +		return -EINVAL;
> +	}
> +	if (rss_conf.rss_key == NULL)
> +		rss_conf.rss_key = rss_intel_key; /* Default hash key */
> +	ixgbe_hw_rss_hash_set(hw, &rss_conf);
> +
> +	rte_memcpy(&filter_info->rss_info,
> +		conf, sizeof(struct ixgbe_rte_flow_rss_conf));
> +
> +	return 0;
> +}
> +
>  /* Stubs needed for linkage when CONFIG_RTE_IXGBE_INC_VECTOR is set
> to 'n' */  int __attribute__((weak))
> ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused
> *dev)
> --
> 2.9.3

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v3 2/2] net/ixgbe: move RSS to flow API
  2017-12-07  9:19       ` Dai, Wei
@ 2017-12-08  2:27         ` Zhao1, Wei
  2017-12-21  3:11           ` Zhang, Helin
  0 siblings, 1 reply; 28+ messages in thread
From: Zhao1, Wei @ 2017-12-08  2:27 UTC (permalink / raw)
  To: Dai, Wei, dev

Hi, daiwei
	I  build the code with ICC for second time, it can pass build and there is no build error.
It seems the icc report is not credible.

> -----Original Message-----
> From: Dai, Wei
> Sent: Thursday, December 7, 2017 5:20 PM
> To: Zhao1, Wei <wei.zhao1@intel.com>; dev@dpdk.org
> Cc: Zhao1, Wei <wei.zhao1@intel.com>
> Subject: RE: [dpdk-dev] [PATCH v3 2/2] net/ixgbe: move RSS to flow API
> 
> Hi, Zhao Wei
> Please correct build error show in http://dpdk.org/ml/archives/test-
> report/2017-November/035130.html
> 
> > -----Original Message-----
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Wei Zhao
> > Sent: Friday, November 24, 2017 4:05 PM
> > To: dev@dpdk.org
> > Cc: Zhao1, Wei <wei.zhao1@intel.com>
> > Subject: [dpdk-dev] [PATCH v3 2/2] net/ixgbe: move RSS to flow API
> >
> > Rte_flow actually defined to include RSS, but till now, RSS is out of rte_flow.
> > This patch is to move ixgbe existing RSS to rte_flow.
> >
> > Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
> > ---
> >  drivers/net/ixgbe/ixgbe_ethdev.c |  13 +++
> > drivers/net/ixgbe/ixgbe_ethdev.h |  10 +++
> >  drivers/net/ixgbe/ixgbe_flow.c   | 165
> > +++++++++++++++++++++++++++++++++++++++
> >  drivers/net/ixgbe/ixgbe_rxtx.c   |  65 +++++++++++++++
> >  4 files changed, 253 insertions(+)
> >
> > diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c
> > b/drivers/net/ixgbe/ixgbe_ethdev.c
> > index ff19a56..4960650 100644
> > --- a/drivers/net/ixgbe/ixgbe_ethdev.c
> > +++ b/drivers/net/ixgbe/ixgbe_ethdev.c
> > @@ -8339,6 +8339,18 @@ ixgbe_l2_tn_filter_restore(struct rte_eth_dev
> > *dev)
> >  	}
> >  }
> >
> > +/* restore rss filter */
> > +static inline void
> > +ixgbe_rss_filter_restore(struct rte_eth_dev *dev) {
> > +	struct ixgbe_filter_info *filter_info =
> > +		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data-
> >dev_private);
> > +
> > +	if (filter_info->rss_info.num)
> > +		ixgbe_config_rss_filter(dev,
> > +			&filter_info->rss_info, TRUE);
> > +}
> > +
> >  static int
> >  ixgbe_filter_restore(struct rte_eth_dev *dev)  { @@ -8347,6 +8359,7
> > @@ ixgbe_filter_restore(struct rte_eth_dev *dev)
> >  	ixgbe_syn_filter_restore(dev);
> >  	ixgbe_fdir_filter_restore(dev);
> >  	ixgbe_l2_tn_filter_restore(dev);
> > +	ixgbe_rss_filter_restore(dev);
> >
> >  	return 0;
> >  }
> > diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h
> > b/drivers/net/ixgbe/ixgbe_ethdev.h
> > index 51ddcfd..4af79b4 100644
> > --- a/drivers/net/ixgbe/ixgbe_ethdev.h
> > +++ b/drivers/net/ixgbe/ixgbe_ethdev.h
> > @@ -224,6 +224,12 @@ struct ixgbe_hw_fdir_info {
> >  	bool mask_added; /* If already got mask from consistent filter */
> > };
> >
> > +struct ixgbe_rte_flow_rss_conf {
> > +	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
> > +	uint16_t num; /**< Number of entries in queue[]. */
> > +	uint16_t queue[IXGBE_MAX_RX_QUEUE_NUM]; /**< Queues
> indices to
> > use. */
> > +};
> > +
> >  /* structure for interrupt relative data */  struct ixgbe_interrupt {
> >  	uint32_t flags;
> > @@ -340,6 +346,8 @@ struct ixgbe_filter_info {
> >  	struct ixgbe_5tuple_filter_list fivetuple_list;
> >  	/* store the SYN filter info */
> >  	uint32_t syn_info;
> > +	/* store the rss filter info */
> > +	struct ixgbe_rte_flow_rss_conf rss_info;
> >  };
> >
> >  struct ixgbe_l2_tn_key {
> > @@ -719,6 +727,8 @@ void ixgbe_tm_conf_init(struct rte_eth_dev *dev);
> > void ixgbe_tm_conf_uninit(struct rte_eth_dev *dev);  int
> > ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev, uint16_t queue_idx,
> >  			       uint16_t tx_rate);
> > +int ixgbe_config_rss_filter(struct rte_eth_dev *dev,
> > +		struct ixgbe_rte_flow_rss_conf *conf, bool add);
> >
> >  static inline int
> >  ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info,
> > diff --git a/drivers/net/ixgbe/ixgbe_flow.c
> > b/drivers/net/ixgbe/ixgbe_flow.c index 19c2d47..8f964cf 100644
> > --- a/drivers/net/ixgbe/ixgbe_flow.c
> > +++ b/drivers/net/ixgbe/ixgbe_flow.c
> > @@ -103,6 +103,11 @@ struct ixgbe_eth_l2_tunnel_conf_ele {
> >  	TAILQ_ENTRY(ixgbe_eth_l2_tunnel_conf_ele) entries;
> >  	struct rte_eth_l2_tunnel_conf filter_info;  };
> > +/* rss filter list structure */
> > +struct ixgbe_rss_conf_ele {
> > +	TAILQ_ENTRY(ixgbe_rss_conf_ele) entries;
> > +	struct ixgbe_rte_flow_rss_conf filter_info; };
> >  /* ixgbe_flow memory list structure */  struct ixgbe_flow_mem {
> >  	TAILQ_ENTRY(ixgbe_flow_mem) entries; @@ -114,6 +119,7 @@
> > TAILQ_HEAD(ixgbe_ethertype_filter_list,
> > ixgbe_ethertype_filter_ele);  TAILQ_HEAD(ixgbe_syn_filter_list,
> > ixgbe_eth_syn_filter_ele);  TAILQ_HEAD(ixgbe_fdir_rule_filter_list,
> > ixgbe_fdir_rule_ele);  TAILQ_HEAD(ixgbe_l2_tunnel_filter_list,
> > ixgbe_eth_l2_tunnel_conf_ele);
> > +TAILQ_HEAD(ixgbe_rss_filter_list, ixgbe_rss_conf_ele);
> >  TAILQ_HEAD(ixgbe_flow_mem_list, ixgbe_flow_mem);
> >
> >  static struct ixgbe_ntuple_filter_list filter_ntuple_list; @@ -121,6
> > +127,7 @@ static struct ixgbe_ethertype_filter_list
> > filter_ethertype_list;  static struct ixgbe_syn_filter_list
> > filter_syn_list;  static struct ixgbe_fdir_rule_filter_list
> > filter_fdir_list;  static struct ixgbe_l2_tunnel_filter_list
> > filter_l2_tunnel_list;
> > +static struct ixgbe_rss_filter_list filter_rss_list;
> >  static struct ixgbe_flow_mem_list ixgbe_flow_list;
> >
> >  /**
> > @@ -2700,6 +2707,109 @@ ixgbe_parse_fdir_filter(struct rte_eth_dev
> > *dev,
> >  	return ret;
> >  }
> >
> > +static int
> > +ixgbe_parse_rss_filter(struct rte_eth_dev *dev,
> > +			const struct rte_flow_attr *attr,
> > +			const struct rte_flow_action actions[],
> > +			struct ixgbe_rte_flow_rss_conf *rss_conf,
> > +			struct rte_flow_error *error)
> > +{
> > +	const struct rte_flow_action *act;
> > +	const struct rte_flow_action_rss *rss;
> > +	uint16_t n;
> > +
> > +	/**
> > +	 * rss only supports forwarding,
> > +	 * check if the first not void action is RSS.
> > +	 */
> > +	act = next_no_void_action(actions, NULL);
> > +	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
> > +		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> > +		rte_flow_error_set(error, EINVAL,
> > +			RTE_FLOW_ERROR_TYPE_ACTION,
> > +			act, "Not supported action.");
> > +		return -rte_errno;
> > +	}
> > +
> > +	rss = (const struct rte_flow_action_rss *)act->conf;
> > +
> > +	if (!rss || !rss->num) {
> > +		rte_flow_error_set(error, EINVAL,
> > +				RTE_FLOW_ERROR_TYPE_ACTION,
> > +				act,
> > +			   "no valid queues");
> > +		return -rte_errno;
> > +	}
> > +
> > +	for (n = 0; n < rss->num; n++) {
> > +		if (rss->queue[n] >= dev->data->nb_rx_queues) {
> > +			rte_flow_error_set(error, EINVAL,
> > +				   RTE_FLOW_ERROR_TYPE_ACTION,
> > +				   act,
> > +				   "queue id > max number of queues");
> > +			return -rte_errno;
> > +		}
> > +	}
> > +	if (rss->rss_conf)
> > +		rss_conf->rss_conf = *rss->rss_conf;
> > +	else
> > +		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
> > +
> > +	for (n = 0; n < rss->num; ++n)
> > +		rss_conf->queue[n] = rss->queue[n];
> > +	rss_conf->num = rss->num;
> > +
> > +	/* check if the next not void item is END */
> > +	act = next_no_void_action(actions, act);
> > +	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
> > +		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
> > +		rte_flow_error_set(error, EINVAL,
> > +			RTE_FLOW_ERROR_TYPE_ACTION,
> > +			act, "Not supported action.");
> > +		return -rte_errno;
> > +	}
> > +
> > +	/* parse attr */
> > +	/* must be input direction */
> > +	if (!attr->ingress) {
> > +		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> > +		rte_flow_error_set(error, EINVAL,
> > +				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
> > +				   attr, "Only support ingress.");
> > +		return -rte_errno;
> > +	}
> > +
> > +	/* not supported */
> > +	if (attr->egress) {
> > +		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> > +		rte_flow_error_set(error, EINVAL,
> > +				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
> > +				   attr, "Not support egress.");
> > +		return -rte_errno;
> > +	}
> > +
> > +	if (attr->priority > 0xFFFF) {
> > +		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> > +		rte_flow_error_set(error, EINVAL,
> > +				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
> > +				   attr, "Error priority.");
> > +		return -rte_errno;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +/* remove the rss filter */
> > +static void
> > +ixgbe_clear_rss_filter(struct rte_eth_dev *dev) {
> > +	struct ixgbe_filter_info *filter_info =
> > +		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data-
> >dev_private);
> > +
> > +	if (filter_info->rss_info.num)
> > +		ixgbe_config_rss_filter(dev, &filter_info->rss_info, FALSE); }
> > +
> >  void
> >  ixgbe_filterlist_init(void)
> >  {
> > @@ -2708,6 +2818,7 @@ ixgbe_filterlist_init(void)
> >  	TAILQ_INIT(&filter_syn_list);
> >  	TAILQ_INIT(&filter_fdir_list);
> >  	TAILQ_INIT(&filter_l2_tunnel_list);
> > +	TAILQ_INIT(&filter_rss_list);
> >  	TAILQ_INIT(&ixgbe_flow_list);
> >  }
> >
> > @@ -2720,6 +2831,7 @@ ixgbe_filterlist_flush(void)
> >  	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
> >  	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
> >  	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
> > +	struct ixgbe_rss_conf_ele *rss_filter_ptr;
> >
> >  	while ((ntuple_filter_ptr = TAILQ_FIRST(&filter_ntuple_list))) {
> >  		TAILQ_REMOVE(&filter_ntuple_list,
> > @@ -2756,6 +2868,13 @@ ixgbe_filterlist_flush(void)
> >  		rte_free(fdir_rule_ptr);
> >  	}
> >
> > +	while ((rss_filter_ptr = TAILQ_FIRST(&filter_rss_list))) {
> > +		TAILQ_REMOVE(&filter_rss_list,
> > +				 rss_filter_ptr,
> > +				 entries);
> > +		rte_free(rss_filter_ptr);
> > +	}
> > +
> >  	while ((ixgbe_flow_mem_ptr = TAILQ_FIRST(&ixgbe_flow_list))) {
> >  		TAILQ_REMOVE(&ixgbe_flow_list,
> >  				 ixgbe_flow_mem_ptr,
> > @@ -2786,12 +2905,14 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
> >  	struct rte_eth_l2_tunnel_conf l2_tn_filter;
> >  	struct ixgbe_hw_fdir_info *fdir_info =
> >  		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data-
> >dev_private);
> > +	struct ixgbe_rte_flow_rss_conf rss_conf;
> >  	struct rte_flow *flow = NULL;
> >  	struct ixgbe_ntuple_filter_ele *ntuple_filter_ptr;
> >  	struct ixgbe_ethertype_filter_ele *ethertype_filter_ptr;
> >  	struct ixgbe_eth_syn_filter_ele *syn_filter_ptr;
> >  	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
> >  	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
> > +	struct ixgbe_rss_conf_ele *rss_filter_ptr;
> >  	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
> >  	uint8_t first_mask = FALSE;
> >
> > @@ -2992,6 +3113,29 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
> >  		}
> >  	}
> >
> > +	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> > +	ret = ixgbe_parse_rss_filter(dev, attr,
> > +					actions, &rss_conf, error);
> > +	if (!ret) {
> > +		ret = ixgbe_config_rss_filter(dev, &rss_conf, TRUE);
> > +		if (!ret) {
> > +			rss_filter_ptr = rte_zmalloc("ixgbe_rss_filter",
> > +				sizeof(struct ixgbe_rss_conf_ele), 0);
> > +			if (!rss_filter_ptr) {
> > +				PMD_DRV_LOG(ERR, "failed to allocate
> memory");
> > +				goto out;
> > +			}
> > +			rte_memcpy(&rss_filter_ptr->filter_info,
> > +				&rss_conf,
> > +				sizeof(struct ixgbe_rte_flow_rss_conf));
> > +			TAILQ_INSERT_TAIL(&filter_rss_list,
> > +				rss_filter_ptr, entries);
> > +			flow->rule = rss_filter_ptr;
> > +			flow->filter_type = RTE_ETH_FILTER_HASH;
> > +			return flow;
> > +		}
> > +	}
> > +
> >  out:
> >  	TAILQ_REMOVE(&ixgbe_flow_list,
> >  		ixgbe_flow_mem_ptr, entries);
> > @@ -3020,6 +3164,7 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
> >  	struct rte_eth_syn_filter syn_filter;
> >  	struct rte_eth_l2_tunnel_conf l2_tn_filter;
> >  	struct ixgbe_fdir_rule fdir_rule;
> > +	struct ixgbe_rte_flow_rss_conf rss_conf;
> >  	int ret;
> >
> >  	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter)); @@
> > -3049,6 +3194,12 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
> >  	memset(&l2_tn_filter, 0, sizeof(struct rte_eth_l2_tunnel_conf));
> >  	ret = ixgbe_parse_l2_tn_filter(dev, attr, pattern,
> >  				actions, &l2_tn_filter, error);
> > +	if (!ret)
> > +		return 0;
> > +
> > +	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
> > +	ret = ixgbe_parse_rss_filter(dev, attr,
> > +					actions, &rss_conf, error);
> >
> >  	return ret;
> >  }
> > @@ -3075,6 +3226,7 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
> >  	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
> >  	struct ixgbe_hw_fdir_info *fdir_info =
> >  		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data-
> >dev_private);
> > +	struct ixgbe_rss_conf_ele *rss_filter_ptr;
> >
> >  	switch (filter_type) {
> >  	case RTE_ETH_FILTER_NTUPLE:
> > @@ -3143,6 +3295,17 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
> >  			rte_free(l2_tn_filter_ptr);
> >  		}
> >  		break;
> > +	case RTE_ETH_FILTER_HASH:
> > +		rss_filter_ptr = (struct ixgbe_rss_conf_ele *)
> > +				pmd_flow->rule;
> > +		ret = ixgbe_config_rss_filter(dev,
> > +					&rss_filter_ptr->filter_info, FALSE);
> > +		if (!ret) {
> > +			TAILQ_REMOVE(&filter_rss_list,
> > +				rss_filter_ptr, entries);
> > +			rte_free(rss_filter_ptr);
> > +		}
> > +		break;
> >  	default:
> >  		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
> >  			    filter_type);
> > @@ -3194,6 +3357,8 @@ ixgbe_flow_flush(struct rte_eth_dev *dev,
> >  		return ret;
> >  	}
> >
> > +	ixgbe_clear_rss_filter(dev);
> > +
> >  	ixgbe_filterlist_flush();
> >
> >  	return 0;
> > diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c
> > b/drivers/net/ixgbe/ixgbe_rxtx.c index 9bc8462..4b38247 100644
> > --- a/drivers/net/ixgbe/ixgbe_rxtx.c
> > +++ b/drivers/net/ixgbe/ixgbe_rxtx.c
> > @@ -5550,6 +5550,71 @@ ixgbevf_dev_rxtx_start(struct rte_eth_dev
> *dev)
> >  	}
> >  }
> >
> > +int
> > +ixgbe_config_rss_filter(struct rte_eth_dev *dev,
> > +		struct ixgbe_rte_flow_rss_conf *conf, bool add) {
> > +	struct ixgbe_hw *hw;
> > +	uint32_t reta;
> > +	uint16_t i;
> > +	uint16_t j;
> > +	uint16_t sp_reta_size;
> > +	uint32_t reta_reg;
> > +	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
> > +	struct ixgbe_filter_info *filter_info =
> > +		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data-
> >dev_private);
> > +
> > +	PMD_INIT_FUNC_TRACE();
> > +	hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> > +
> > +	sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
> > +
> > +	if (!add) {
> > +		if (memcmp(conf, &filter_info->rss_info,
> > +			sizeof(struct ixgbe_rte_flow_rss_conf)) == 0) {
> > +			ixgbe_rss_disable(dev);
> > +			memset(&filter_info->rss_info, 0,
> > +				sizeof(struct ixgbe_rte_flow_rss_conf));
> > +			return 0;
> > +		}
> > +		return -EINVAL;
> > +	}
> > +
> > +	if (filter_info->rss_info.num)
> > +		return -EINVAL;
> > +	/* Fill in redirection table
> > +	 * The byte-swap is needed because NIC registers are in
> > +	 * little-endian order.
> > +	 */
> > +	reta = 0;
> > +	for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
> > +		reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
> > +
> > +		if (j == conf->num)
> > +			j = 0;
> > +		reta = (reta << 8) | conf->queue[j];
> > +		if ((i & 3) == 3)
> > +			IXGBE_WRITE_REG(hw, reta_reg,
> > +					rte_bswap32(reta));
> > +	}
> > +
> > +	/* Configure the RSS key and the RSS protocols used to compute
> > +	 * the RSS hash of input packets.
> > +	 */
> > +	if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
> > +		ixgbe_rss_disable(dev);
> > +		return -EINVAL;
> > +	}
> > +	if (rss_conf.rss_key == NULL)
> > +		rss_conf.rss_key = rss_intel_key; /* Default hash key */
> > +	ixgbe_hw_rss_hash_set(hw, &rss_conf);
> > +
> > +	rte_memcpy(&filter_info->rss_info,
> > +		conf, sizeof(struct ixgbe_rte_flow_rss_conf));
> > +
> > +	return 0;
> > +}
> > +
> >  /* Stubs needed for linkage when CONFIG_RTE_IXGBE_INC_VECTOR is set
> > to 'n' */  int __attribute__((weak))
> > ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev
> __rte_unused
> > *dev)
> > --
> > 2.9.3

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v3 1/2] net/e1000: move RSS to flow API
  2017-12-07  9:19       ` Dai, Wei
@ 2017-12-08  2:28         ` Zhao1, Wei
  2017-12-21  3:11           ` Zhang, Helin
  0 siblings, 1 reply; 28+ messages in thread
From: Zhao1, Wei @ 2017-12-08  2:28 UTC (permalink / raw)
  To: Dai, Wei, dev

Hi, daiwei
	I  build the code with ICC for second time just now, it can pass build and there is no build error.
It seems the icc report is not credible.


> -----Original Message-----
> From: Dai, Wei
> Sent: Thursday, December 7, 2017 5:19 PM
> To: Zhao1, Wei <wei.zhao1@intel.com>; dev@dpdk.org
> Cc: Zhao1, Wei <wei.zhao1@intel.com>
> Subject: RE: [dpdk-dev] [PATCH v3 1/2] net/e1000: move RSS to flow API
> 
> Hi, Zhao Wei
> Please correct build error show in http://dpdk.org/ml/archives/test-
> report/2017-November/035129.html
> 
> 
> > -----Original Message-----
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Wei Zhao
> > Sent: Friday, November 24, 2017 4:05 PM
> > To: dev@dpdk.org
> > Cc: Zhao1, Wei <wei.zhao1@intel.com>
> > Subject: [dpdk-dev] [PATCH v3 1/2] net/e1000: move RSS to flow API
> >
> > Rte_flow actually defined to include RSS, but till now, RSS is out of rte_flow.
> > This patch is to move igb existing RSS to rte_flow.
> >
> > Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
> > ---
> >  drivers/net/e1000/e1000_ethdev.h |  20 +++++
> >  drivers/net/e1000/igb_ethdev.c   |  17 +++++
> >  drivers/net/e1000/igb_flow.c     | 160
> > +++++++++++++++++++++++++++++++++++++++
> >  drivers/net/e1000/igb_rxtx.c     |  61 +++++++++++++++
> >  4 files changed, 258 insertions(+)
> >
> > diff --git a/drivers/net/e1000/e1000_ethdev.h
> > b/drivers/net/e1000/e1000_ethdev.h
> > index 5668910..0731766 100644
> > --- a/drivers/net/e1000/e1000_ethdev.h
> > +++ b/drivers/net/e1000/e1000_ethdev.h
> > @@ -257,6 +257,12 @@ struct igb_ethertype_filter {
> >  	uint32_t etqf;
> >  };
> >
> > +struct igb_rte_flow_rss_conf {
> > +	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
> > +	uint16_t num; /**< Number of entries in queue[]. */
> > +	uint16_t queue[IGB_MAX_RX_QUEUE_NUM]; /**< Queues indices
> to
> > use. */
> > +};
> > +
> >  /*
> >   * Structure to store filters'info.
> >   */
> > @@ -274,6 +280,8 @@ struct e1000_filter_info {
> >  	struct e1000_2tuple_filter_list twotuple_list;
> >  	/* store the SYN filter info */
> >  	uint32_t syn_info;
> > +	/* store the rss filter info */
> > +	struct igb_rte_flow_rss_conf rss_info;
> >  };
> >
> >  /*
> > @@ -342,6 +350,12 @@ struct igb_flex_filter_ele {
> >  	struct rte_eth_flex_filter filter_info;  };
> >
> > +/* rss filter  list structure */
> > +struct igb_rss_conf_ele {
> > +	TAILQ_ENTRY(igb_rss_conf_ele) entries;
> > +	struct igb_rte_flow_rss_conf filter_info; };
> > +
> >  /* igb_flow memory list structure */
> >  struct igb_flow_mem {
> >  	TAILQ_ENTRY(igb_flow_mem) entries;
> > @@ -357,6 +371,8 @@ TAILQ_HEAD(igb_syn_filter_list,
> > igb_eth_syn_filter_ele);  struct igb_syn_filter_list
> > igb_filter_syn_list; TAILQ_HEAD(igb_flex_filter_list,
> > igb_flex_filter_ele);  struct igb_flex_filter_list
> > igb_filter_flex_list;
> > +TAILQ_HEAD(igb_rss_filter_list, igb_rss_conf_ele); struct
> > +igb_rss_filter_list igb_filter_rss_list;
> >  TAILQ_HEAD(igb_flow_mem_list, igb_flow_mem);  struct
> > igb_flow_mem_list igb_flow_list;
> >
> > @@ -500,4 +516,8 @@ int eth_igb_syn_filter_set(struct rte_eth_dev
> > *dev, int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
> >  			struct rte_eth_flex_filter *filter,
> >  			bool add);
> > +int igb_config_rss_filter(struct rte_eth_dev *dev,
> > +			struct igb_rte_flow_rss_conf *conf,
> > +			bool add);
> > +
> >  #endif /* _E1000_ETHDEV_H_ */
> > diff --git a/drivers/net/e1000/igb_ethdev.c
> > b/drivers/net/e1000/igb_ethdev.c index fdc139f..275fa02 100644
> > --- a/drivers/net/e1000/igb_ethdev.c
> > +++ b/drivers/net/e1000/igb_ethdev.c
> > @@ -948,6 +948,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
> >  	TAILQ_INIT(&igb_filter_ethertype_list);
> >  	TAILQ_INIT(&igb_filter_syn_list);
> >  	TAILQ_INIT(&igb_filter_flex_list);
> > +	TAILQ_INIT(&igb_filter_rss_list);
> >  	TAILQ_INIT(&igb_flow_list);
> >
> >  	return 0;
> > @@ -1007,6 +1008,10 @@ eth_igb_dev_uninit(struct rte_eth_dev
> *eth_dev)
> >  	memset(filter_info->ethertype_filters, 0,
> >  		E1000_MAX_ETQF_FILTERS * sizeof(struct
> igb_ethertype_filter));
> >
> > +	/* clear the rss filter info */
> > +	memset(&filter_info->rss_info, 0,
> > +		sizeof(struct igb_rte_flow_rss_conf));
> > +
> >  	/* remove all ntuple filters of the device */
> >  	igb_ntuple_filter_uninit(eth_dev);
> >
> > @@ -5628,6 +5633,17 @@ igb_flex_filter_restore(struct rte_eth_dev *dev)
> >  	}
> >  }
> >
> > +/* restore rss filter */
> > +static inline void
> > +igb_rss_filter_restore(struct rte_eth_dev *dev) {
> > +	struct e1000_filter_info *filter_info =
> > +		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data-
> >dev_private);
> > +
> > +	if (filter_info->rss_info.num)
> > +		igb_config_rss_filter(dev, &filter_info->rss_info, TRUE); }
> > +
> >  /* restore all types filter */
> >  static int
> >  igb_filter_restore(struct rte_eth_dev *dev) @@ -5636,6 +5652,7 @@
> > igb_filter_restore(struct rte_eth_dev *dev)
> >  	igb_ethertype_filter_restore(dev);
> >  	igb_syn_filter_restore(dev);
> >  	igb_flex_filter_restore(dev);
> > +	igb_rss_filter_restore(dev);
> >
> >  	return 0;
> >  }
> > diff --git a/drivers/net/e1000/igb_flow.c
> > b/drivers/net/e1000/igb_flow.c index 22bad26..bf5cfac 100644
> > --- a/drivers/net/e1000/igb_flow.c
> > +++ b/drivers/net/e1000/igb_flow.c
> > @@ -1295,6 +1295,101 @@ igb_parse_flex_filter(struct rte_eth_dev *dev,
> >  	return 0;
> >  }
> >
> > +static int
> > +igb_parse_rss_filter(struct rte_eth_dev *dev,
> > +			const struct rte_flow_attr *attr,
> > +			const struct rte_flow_action actions[],
> > +			struct igb_rte_flow_rss_conf *rss_conf,
> > +			struct rte_flow_error *error)
> > +{
> > +	const struct rte_flow_action *act;
> > +	const struct rte_flow_action_rss *rss;
> > +	uint16_t n, index;
> > +
> > +	/**
> > +	 * rss only supports forwarding,
> > +	 * check if the first not void action is RSS.
> > +	 */
> > +	index = 0;
> > +	NEXT_ITEM_OF_ACTION(act, actions, index);
> > +	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
> > +		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> > +		rte_flow_error_set(error, EINVAL,
> > +			RTE_FLOW_ERROR_TYPE_ACTION,
> > +			act, "Not supported action.");
> > +		return -rte_errno;
> > +	}
> > +
> > +	rss = (const struct rte_flow_action_rss *)act->conf;
> > +
> > +	if (!rss || !rss->num) {
> > +		rte_flow_error_set(error, EINVAL,
> > +				RTE_FLOW_ERROR_TYPE_ACTION,
> > +				act,
> > +			   "no valid queues");
> > +		return -rte_errno;
> > +	}
> > +
> > +	for (n = 0; n < rss->num; n++) {
> > +		if (rss->queue[n] >= dev->data->nb_rx_queues) {
> > +			rte_flow_error_set(error, EINVAL,
> > +				   RTE_FLOW_ERROR_TYPE_ACTION,
> > +				   act,
> > +				   "queue id > max number of queues");
> > +			return -rte_errno;
> > +		}
> > +	}
> > +
> > +	if (rss->rss_conf)
> > +		rss_conf->rss_conf = *rss->rss_conf;
> > +	else
> > +		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
> > +
> > +	for (n = 0; n < rss->num; ++n)
> > +		rss_conf->queue[n] = rss->queue[n];
> > +	rss_conf->num = rss->num;
> > +
> > +	/* check if the next not void item is END */
> > +	index++;
> > +	NEXT_ITEM_OF_ACTION(act, actions, index);
> > +	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
> > +		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
> > +		rte_flow_error_set(error, EINVAL,
> > +			RTE_FLOW_ERROR_TYPE_ACTION,
> > +			act, "Not supported action.");
> > +		return -rte_errno;
> > +	}
> > +
> > +	/* parse attr */
> > +	/* must be input direction */
> > +	if (!attr->ingress) {
> > +		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> > +		rte_flow_error_set(error, EINVAL,
> > +				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
> > +				   attr, "Only support ingress.");
> > +		return -rte_errno;
> > +	}
> > +
> > +	/* not supported */
> > +	if (attr->egress) {
> > +		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> > +		rte_flow_error_set(error, EINVAL,
> > +				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
> > +				   attr, "Not support egress.");
> > +		return -rte_errno;
> > +	}
> > +
> > +	if (attr->priority > 0xFFFF) {
> > +		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> > +		rte_flow_error_set(error, EINVAL,
> > +				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
> > +				   attr, "Error priority.");
> > +		return -rte_errno;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >  /**
> >   * Create a flow rule.
> >   * Theorically one rule can match more than one filters.
> > @@ -1313,11 +1408,13 @@ igb_flow_create(struct rte_eth_dev *dev,
> >  	struct rte_eth_ethertype_filter ethertype_filter;
> >  	struct rte_eth_syn_filter syn_filter;
> >  	struct rte_eth_flex_filter flex_filter;
> > +	struct igb_rte_flow_rss_conf rss_conf;
> >  	struct rte_flow *flow = NULL;
> >  	struct igb_ntuple_filter_ele *ntuple_filter_ptr;
> >  	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
> >  	struct igb_eth_syn_filter_ele *syn_filter_ptr;
> >  	struct igb_flex_filter_ele *flex_filter_ptr;
> > +	struct igb_rss_conf_ele *rss_filter_ptr;
> >  	struct igb_flow_mem *igb_flow_mem_ptr;
> >
> >  	flow = rte_zmalloc("igb_rte_flow", sizeof(struct rte_flow), 0); @@
> > -1419,6 +1516,29 @@ igb_flow_create(struct rte_eth_dev *dev,
> >  		}
> >  	}
> >
> > +	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> > +	ret = igb_parse_rss_filter(dev, attr,
> > +					actions, &rss_conf, error);
> > +	if (!ret) {
> > +		ret = igb_config_rss_filter(dev, &rss_conf, TRUE);
> > +		if (!ret) {
> > +			rss_filter_ptr = rte_zmalloc("igb_rss_filter",
> > +				sizeof(struct igb_rss_conf_ele), 0);
> > +			if (!rss_filter_ptr) {
> > +				PMD_DRV_LOG(ERR, "failed to allocate
> memory");
> > +				goto out;
> > +			}
> > +			rte_memcpy(&rss_filter_ptr->filter_info,
> > +				&rss_conf,
> > +				sizeof(struct igb_rte_flow_rss_conf));
> > +			TAILQ_INSERT_TAIL(&igb_filter_rss_list,
> > +				rss_filter_ptr, entries);
> > +			flow->rule = rss_filter_ptr;
> > +			flow->filter_type = RTE_ETH_FILTER_HASH;
> > +			return flow;
> > +		}
> > +	}
> > +
> >  out:
> >  	TAILQ_REMOVE(&igb_flow_list,
> >  		igb_flow_mem_ptr, entries);
> > @@ -1446,6 +1566,7 @@ igb_flow_validate(__rte_unused struct
> > rte_eth_dev *dev,
> >  	struct rte_eth_ethertype_filter ethertype_filter;
> >  	struct rte_eth_syn_filter syn_filter;
> >  	struct rte_eth_flex_filter flex_filter;
> > +	struct igb_rte_flow_rss_conf rss_conf;
> >  	int ret;
> >
> >  	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter)); @@
> > -1469,6 +1590,12 @@ igb_flow_validate(__rte_unused struct rte_eth_dev
> > *dev,
> >  	memset(&flex_filter, 0, sizeof(struct rte_eth_flex_filter));
> >  	ret = igb_parse_flex_filter(dev, attr, pattern,
> >  				actions, &flex_filter, error);
> > +	if (!ret)
> > +		return 0;
> > +
> > +	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
> > +	ret = igb_parse_rss_filter(dev, attr,
> > +					actions, &rss_conf, error);
> >
> >  	return ret;
> >  }
> > @@ -1487,6 +1614,7 @@ igb_flow_destroy(struct rte_eth_dev *dev,
> >  	struct igb_eth_syn_filter_ele *syn_filter_ptr;
> >  	struct igb_flex_filter_ele *flex_filter_ptr;
> >  	struct igb_flow_mem *igb_flow_mem_ptr;
> > +	struct igb_rss_conf_ele *rss_filter_ptr;
> >
> >  	switch (filter_type) {
> >  	case RTE_ETH_FILTER_NTUPLE:
> > @@ -1533,6 +1661,17 @@ igb_flow_destroy(struct rte_eth_dev *dev,
> >  			rte_free(flex_filter_ptr);
> >  		}
> >  		break;
> > +	case RTE_ETH_FILTER_HASH:
> > +		rss_filter_ptr = (struct igb_rss_conf_ele *)
> > +				pmd_flow->rule;
> > +		ret = igb_config_rss_filter(dev,
> > +					&rss_filter_ptr->filter_info, FALSE);
> > +		if (!ret) {
> > +			TAILQ_REMOVE(&igb_filter_rss_list,
> > +				rss_filter_ptr, entries);
> > +			rte_free(rss_filter_ptr);
> > +		}
> > +		break;
> >  	default:
> >  		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
> >  			    filter_type);
> > @@ -1621,6 +1760,17 @@ igb_clear_all_flex_filter(struct rte_eth_dev
> *dev)
> >  		igb_remove_flex_filter(dev, flex_filter);  }
> >
> > +/* remove the rss filter */
> > +static void
> > +igb_clear_rss_filter(struct rte_eth_dev *dev) {
> > +	struct e1000_filter_info *filter =
> > +		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data-
> >dev_private);
> > +
> > +	if (filter->rss_info.num)
> > +		igb_config_rss_filter(dev, &filter->rss_info, FALSE); }
> > +
> >  void
> >  igb_filterlist_flush(struct rte_eth_dev *dev)  { @@ -1628,6 +1778,7
> > @@ igb_filterlist_flush(struct rte_eth_dev *dev)
> >  	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
> >  	struct igb_eth_syn_filter_ele *syn_filter_ptr;
> >  	struct igb_flex_filter_ele *flex_filter_ptr;
> > +	struct igb_rss_conf_ele  *rss_filter_ptr;
> >  	struct igb_flow_mem *igb_flow_mem_ptr;
> >  	enum rte_filter_type filter_type;
> >  	struct rte_flow *pmd_flow;
> > @@ -1670,6 +1821,14 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
> >  						flex_filter_ptr, entries);
> >  				rte_free(flex_filter_ptr);
> >  				break;
> > +			case RTE_ETH_FILTER_HASH:
> > +				rss_filter_ptr =
> > +					(struct igb_rss_conf_ele *)
> > +						pmd_flow->rule;
> > +				TAILQ_REMOVE(&igb_filter_rss_list,
> > +						rss_filter_ptr, entries);
> > +				rte_free(rss_filter_ptr);
> > +				break;
> >  			default:
> >  				PMD_DRV_LOG(WARNING, "Filter type"
> >  					"(%d) not supported", filter_type);
> @@ -1693,6
> > +1852,7 @@ igb_flow_flush(struct rte_eth_dev *dev,
> >  	igb_clear_all_ethertype_filter(dev);
> >  	igb_clear_syn_filter(dev);
> >  	igb_clear_all_flex_filter(dev);
> > +	igb_clear_rss_filter(dev);
> >  	igb_filterlist_flush(dev);
> >
> >  	return 0;
> > diff --git a/drivers/net/e1000/igb_rxtx.c
> > b/drivers/net/e1000/igb_rxtx.c index 4ee12e9..af86726 100644
> > --- a/drivers/net/e1000/igb_rxtx.c
> > +++ b/drivers/net/e1000/igb_rxtx.c
> > @@ -2786,3 +2786,64 @@ igb_txq_info_get(struct rte_eth_dev *dev,
> > uint16_t queue_id,
> >  	qinfo->conf.tx_thresh.hthresh = txq->hthresh;
> >  	qinfo->conf.tx_thresh.wthresh = txq->wthresh;  }
> > +
> > +int
> > +igb_config_rss_filter(struct rte_eth_dev *dev,
> > +		struct igb_rte_flow_rss_conf *conf, bool add) {
> > +	uint32_t shift;
> > +	uint16_t i, j;
> > +	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
> > +	struct e1000_filter_info *filter_info =
> > +		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data-
> >dev_private);
> > +	struct e1000_hw *hw =
> > E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> > +
> > +	hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> > +
> > +	if (!add) {
> > +		if (memcmp(conf, &filter_info->rss_info,
> > +			sizeof(struct igb_rte_flow_rss_conf)) == 0) {
> > +			igb_rss_disable(dev);
> > +			memset(&filter_info->rss_info, 0,
> > +				sizeof(struct igb_rte_flow_rss_conf));
> > +			return 0;
> > +		}
> > +		return -EINVAL;
> > +	}
> > +
> > +	if (filter_info->rss_info.num)
> > +		return -EINVAL;
> > +
> > +	/* Fill in redirection table. */
> > +	shift = (hw->mac.type == e1000_82575) ? 6 : 0;
> > +	for (i = 0, j = 0; i < 128; i++, j++) {
> > +		union e1000_reta {
> > +			uint32_t dword;
> > +			uint8_t  bytes[4];
> > +		} reta;
> > +		uint8_t q_idx;
> > +
> > +		q_idx = conf->queue[j];
> > +		if (j == conf->num)
> > +			j = 0;
> > +		reta.bytes[i & 3] = (uint8_t)(q_idx << shift);
> > +		if ((i & 3) == 3)
> > +			E1000_WRITE_REG(hw, E1000_RETA(i >> 2),
> reta.dword);
> > +	}
> > +
> > +	/* Configure the RSS key and the RSS protocols used to compute
> > +	 * the RSS hash of input packets.
> > +	 */
> > +	if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
> > +		igb_rss_disable(dev);
> > +		return 0;
> > +	}
> > +	if (rss_conf.rss_key == NULL)
> > +		rss_conf.rss_key = rss_intel_key; /* Default hash key */
> > +	igb_hw_rss_hash_set(hw, &rss_conf);
> > +
> > +	rte_memcpy(&filter_info->rss_info,
> > +		conf, sizeof(struct igb_rte_flow_rss_conf));
> > +
> > +	return 0;
> > +}
> > --
> > 2.9.3

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v3 1/2] net/e1000: move RSS to flow API
  2017-12-08  2:28         ` Zhao1, Wei
@ 2017-12-21  3:11           ` Zhang, Helin
  2018-01-04  8:48             ` Zhao1, Wei
  0 siblings, 1 reply; 28+ messages in thread
From: Zhang, Helin @ 2017-12-21  3:11 UTC (permalink / raw)
  To: Zhao1, Wei, Dai, Wei, dev



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Zhao1, Wei
> Sent: Friday, December 8, 2017 10:28 AM
> To: Dai, Wei; dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v3 1/2] net/e1000: move RSS to flow API
> 
> Hi, daiwei
> 	I  build the code with ICC for second time just now, it can pass build
> and there is no build error.
> It seems the icc report is not credible.
> 
> 
> > -----Original Message-----
> > From: Dai, Wei
> > Sent: Thursday, December 7, 2017 5:19 PM
> > To: Zhao1, Wei <wei.zhao1@intel.com>; dev@dpdk.org
> > Cc: Zhao1, Wei <wei.zhao1@intel.com>
> > Subject: RE: [dpdk-dev] [PATCH v3 1/2] net/e1000: move RSS to flow API
> >
> > Hi, Zhao Wei
> > Please correct build error show in http://dpdk.org/ml/archives/test-
> > report/2017-November/035129.html
> >
> >
> > > -----Original Message-----
> > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Wei Zhao
> > > Sent: Friday, November 24, 2017 4:05 PM
> > > To: dev@dpdk.org
> > > Cc: Zhao1, Wei <wei.zhao1@intel.com>
> > > Subject: [dpdk-dev] [PATCH v3 1/2] net/e1000: move RSS to flow API
> > >
> > > Rte_flow actually defined to include RSS, but till now, RSS is out of
> rte_flow.
> > > This patch is to move igb existing RSS to rte_flow.
> > >
> > > Signed-off-by: Wei Zhao <wei.zhao1@intel.com>

I think Wei Dai is right, please double check the error reported, and get that fixed.

Thanks,
Helin

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v3 2/2] net/ixgbe: move RSS to flow API
  2017-12-08  2:27         ` Zhao1, Wei
@ 2017-12-21  3:11           ` Zhang, Helin
  2018-01-04  8:51             ` Zhao1, Wei
  0 siblings, 1 reply; 28+ messages in thread
From: Zhang, Helin @ 2017-12-21  3:11 UTC (permalink / raw)
  To: Zhao1, Wei, Dai, Wei, dev



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Zhao1, Wei
> Sent: Friday, December 8, 2017 10:28 AM
> To: Dai, Wei; dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v3 2/2] net/ixgbe: move RSS to flow API
> 
> Hi, daiwei
> 	I  build the code with ICC for second time, it can pass build and there
> is no build error.
> It seems the icc report is not credible.
> 
> > -----Original Message-----
> > From: Dai, Wei
> > Sent: Thursday, December 7, 2017 5:20 PM
> > To: Zhao1, Wei <wei.zhao1@intel.com>; dev@dpdk.org
> > Cc: Zhao1, Wei <wei.zhao1@intel.com>
> > Subject: RE: [dpdk-dev] [PATCH v3 2/2] net/ixgbe: move RSS to flow API
> >
> > Hi, Zhao Wei
> > Please correct build error show in http://dpdk.org/ml/archives/test-
> > report/2017-November/035130.html
> >
> > > -----Original Message-----
> > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Wei Zhao
> > > Sent: Friday, November 24, 2017 4:05 PM
> > > To: dev@dpdk.org
> > > Cc: Zhao1, Wei <wei.zhao1@intel.com>
> > > Subject: [dpdk-dev] [PATCH v3 2/2] net/ixgbe: move RSS to flow API
> > >
> > > Rte_flow actually defined to include RSS, but till now, RSS is out of
> rte_flow.
> > > This patch is to move ixgbe existing RSS to rte_flow.
> > >
> > > Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
I think Wei Dai is right, please double check the error reported, and get that fixed.

Thanks,
Helin

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v4 0/2] move RSS to flow API
  2017-11-24  8:05   ` [PATCH v3 0/2] " Wei Zhao
  2017-11-24  8:05     ` [PATCH v3 1/2] net/e1000: " Wei Zhao
  2017-11-24  8:05     ` [PATCH v3 2/2] net/ixgbe: " Wei Zhao
@ 2018-01-04  7:46     ` Wei Zhao
  2018-01-04  7:46       ` [PATCH v4 1/2] net/e1000: " Wei Zhao
                         ` (2 more replies)
  2 siblings, 3 replies; 28+ messages in thread
From: Wei Zhao @ 2018-01-04  7:46 UTC (permalink / raw)
  To: dev; +Cc: wei.dai

The patches mainly finish following functions:
1) igb move RSS to flow API
2) ixgbe move RSS to flow API

v2:
-fix bug for RSS flush code.
-fix patch check warning.

v3:
-fix bug for ixgbe rss restore.

v4:
-fix build warning and add release notes comment.

Wei Zhao (2):
  net/e1000: move RSS to flow API
  net/ixgbe: move RSS to flow API

 doc/guides/rel_notes/release_18_02.rst |   6 ++
 drivers/net/e1000/e1000_ethdev.h       |  20 ++++
 drivers/net/e1000/igb_ethdev.c         |  17 ++++
 drivers/net/e1000/igb_flow.c           | 160 ++++++++++++++++++++++++++++++++
 drivers/net/e1000/igb_rxtx.c           |  61 ++++++++++++
 drivers/net/ixgbe/ixgbe_ethdev.c       |  13 +++
 drivers/net/ixgbe/ixgbe_ethdev.h       |  10 ++
 drivers/net/ixgbe/ixgbe_flow.c         | 165 +++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_rxtx.c         |  65 +++++++++++++
 9 files changed, 517 insertions(+)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v4 1/2] net/e1000: move RSS to flow API
  2018-01-04  7:46     ` [PATCH v4 0/2] " Wei Zhao
@ 2018-01-04  7:46       ` Wei Zhao
  2018-01-05  6:05         ` Dai, Wei
  2018-01-04  7:46       ` [PATCH v4 2/2] net/ixgbe: " Wei Zhao
  2018-01-09  6:20       ` [PATCH v5 0/2] " Wei Zhao
  2 siblings, 1 reply; 28+ messages in thread
From: Wei Zhao @ 2018-01-04  7:46 UTC (permalink / raw)
  To: dev; +Cc: wei.dai, Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move igb existing RSS to rte_flow.
The old RSS configuration is still reserved.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
---
 doc/guides/rel_notes/release_18_02.rst |   6 ++
 drivers/net/e1000/e1000_ethdev.h       |  20 +++++
 drivers/net/e1000/igb_ethdev.c         |  17 ++++
 drivers/net/e1000/igb_flow.c           | 160 +++++++++++++++++++++++++++++++++
 drivers/net/e1000/igb_rxtx.c           |  61 +++++++++++++
 5 files changed, 264 insertions(+)

diff --git a/doc/guides/rel_notes/release_18_02.rst b/doc/guides/rel_notes/release_18_02.rst
index 24b67bb..1b91508 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -41,6 +41,12 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the igb ethernet driver to support RSS with flow API.**
+
+  Rte_flow actually defined to include RSS, but till now, RSS is out of
+  rte_flow. This patch is to support igb NIC with existing RSS configuration
+  using rte_flow API.
+
 
 API Changes
 -----------
diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index 5668910..0731766 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -257,6 +257,12 @@ struct igb_ethertype_filter {
 	uint32_t etqf;
 };
 
+struct igb_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IGB_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /*
  * Structure to store filters'info.
  */
@@ -274,6 +280,8 @@ struct e1000_filter_info {
 	struct e1000_2tuple_filter_list twotuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct igb_rte_flow_rss_conf rss_info;
 };
 
 /*
@@ -342,6 +350,12 @@ struct igb_flex_filter_ele {
 	struct rte_eth_flex_filter filter_info;
 };
 
+/* rss filter  list structure */
+struct igb_rss_conf_ele {
+	TAILQ_ENTRY(igb_rss_conf_ele) entries;
+	struct igb_rte_flow_rss_conf filter_info;
+};
+
 /* igb_flow memory list structure */
 struct igb_flow_mem {
 	TAILQ_ENTRY(igb_flow_mem) entries;
@@ -357,6 +371,8 @@ TAILQ_HEAD(igb_syn_filter_list, igb_eth_syn_filter_ele);
 struct igb_syn_filter_list igb_filter_syn_list;
 TAILQ_HEAD(igb_flex_filter_list, igb_flex_filter_ele);
 struct igb_flex_filter_list igb_filter_flex_list;
+TAILQ_HEAD(igb_rss_filter_list, igb_rss_conf_ele);
+struct igb_rss_filter_list igb_filter_rss_list;
 TAILQ_HEAD(igb_flow_mem_list, igb_flow_mem);
 struct igb_flow_mem_list igb_flow_list;
 
@@ -500,4 +516,8 @@ int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
 int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
 			struct rte_eth_flex_filter *filter,
 			bool add);
+int igb_config_rss_filter(struct rte_eth_dev *dev,
+			struct igb_rte_flow_rss_conf *conf,
+			bool add);
+
 #endif /* _E1000_ETHDEV_H_ */
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index fdc139f..275fa02 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -948,6 +948,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 	TAILQ_INIT(&igb_filter_ethertype_list);
 	TAILQ_INIT(&igb_filter_syn_list);
 	TAILQ_INIT(&igb_filter_flex_list);
+	TAILQ_INIT(&igb_filter_rss_list);
 	TAILQ_INIT(&igb_flow_list);
 
 	return 0;
@@ -1007,6 +1008,10 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 	memset(filter_info->ethertype_filters, 0,
 		E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
 
+	/* clear the rss filter info */
+	memset(&filter_info->rss_info, 0,
+		sizeof(struct igb_rte_flow_rss_conf));
+
 	/* remove all ntuple filters of the device */
 	igb_ntuple_filter_uninit(eth_dev);
 
@@ -5628,6 +5633,17 @@ igb_flex_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+igb_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		igb_config_rss_filter(dev, &filter_info->rss_info, TRUE);
+}
+
 /* restore all types filter */
 static int
 igb_filter_restore(struct rte_eth_dev *dev)
@@ -5636,6 +5652,7 @@ igb_filter_restore(struct rte_eth_dev *dev)
 	igb_ethertype_filter_restore(dev);
 	igb_syn_filter_restore(dev);
 	igb_flex_filter_restore(dev);
+	igb_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/e1000/igb_flow.c b/drivers/net/e1000/igb_flow.c
index 22bad26..32ad8d2 100644
--- a/drivers/net/e1000/igb_flow.c
+++ b/drivers/net/e1000/igb_flow.c
@@ -1295,6 +1295,101 @@ igb_parse_flex_filter(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+igb_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct igb_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n, index;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	index = 0;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IGB_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	index++;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
 /**
  * Create a flow rule.
  * Theorically one rule can match more than one filters.
@@ -1313,11 +1408,13 @@ igb_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct igb_ntuple_filter_ele *ntuple_filter_ptr;
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 
 	flow = rte_zmalloc("igb_rte_flow", sizeof(struct rte_flow), 0);
@@ -1419,6 +1516,29 @@ igb_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = igb_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("igb_rss_filter",
+				sizeof(struct igb_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct igb_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&igb_flow_list,
 		igb_flow_mem_ptr, entries);
@@ -1446,6 +1566,7 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -1469,6 +1590,12 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	memset(&flex_filter, 0, sizeof(struct rte_eth_flex_filter));
 	ret = igb_parse_flex_filter(dev, attr, pattern,
 				actions, &flex_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -1487,6 +1614,7 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -1533,6 +1661,17 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(flex_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct igb_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = igb_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -1621,6 +1760,17 @@ igb_clear_all_flex_filter(struct rte_eth_dev *dev)
 		igb_remove_flex_filter(dev, flex_filter);
 }
 
+/* remove the rss filter */
+static void
+igb_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter->rss_info.num)
+		igb_config_rss_filter(dev, &filter->rss_info, FALSE);
+}
+
 void
 igb_filterlist_flush(struct rte_eth_dev *dev)
 {
@@ -1628,6 +1778,7 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele  *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 	enum rte_filter_type filter_type;
 	struct rte_flow *pmd_flow;
@@ -1670,6 +1821,14 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 						flex_filter_ptr, entries);
 				rte_free(flex_filter_ptr);
 				break;
+			case RTE_ETH_FILTER_HASH:
+				rss_filter_ptr =
+					(struct igb_rss_conf_ele *)
+						pmd_flow->rule;
+				TAILQ_REMOVE(&igb_filter_rss_list,
+						rss_filter_ptr, entries);
+				rte_free(rss_filter_ptr);
+				break;
 			default:
 				PMD_DRV_LOG(WARNING, "Filter type"
 					"(%d) not supported", filter_type);
@@ -1693,6 +1852,7 @@ igb_flow_flush(struct rte_eth_dev *dev,
 	igb_clear_all_ethertype_filter(dev);
 	igb_clear_syn_filter(dev);
 	igb_clear_all_flex_filter(dev);
+	igb_clear_rss_filter(dev);
 	igb_filterlist_flush(dev);
 
 	return 0;
diff --git a/drivers/net/e1000/igb_rxtx.c b/drivers/net/e1000/igb_rxtx.c
index 4ee12e9..af86726 100644
--- a/drivers/net/e1000/igb_rxtx.c
+++ b/drivers/net/e1000/igb_rxtx.c
@@ -2786,3 +2786,64 @@ igb_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 	qinfo->conf.tx_thresh.hthresh = txq->hthresh;
 	qinfo->conf.tx_thresh.wthresh = txq->wthresh;
 }
+
+int
+igb_config_rss_filter(struct rte_eth_dev *dev,
+		struct igb_rte_flow_rss_conf *conf, bool add)
+{
+	uint32_t shift;
+	uint16_t i, j;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct igb_rte_flow_rss_conf)) == 0) {
+			igb_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct igb_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+
+	/* Fill in redirection table. */
+	shift = (hw->mac.type == e1000_82575) ? 6 : 0;
+	for (i = 0, j = 0; i < 128; i++, j++) {
+		union e1000_reta {
+			uint32_t dword;
+			uint8_t  bytes[4];
+		} reta;
+		uint8_t q_idx;
+
+		q_idx = conf->queue[j];
+		if (j == conf->num)
+			j = 0;
+		reta.bytes[i & 3] = (uint8_t)(q_idx << shift);
+		if ((i & 3) == 3)
+			E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
+		igb_rss_disable(dev);
+		return 0;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	igb_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct igb_rte_flow_rss_conf));
+
+	return 0;
+}
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v4 2/2] net/ixgbe: move RSS to flow API
  2018-01-04  7:46     ` [PATCH v4 0/2] " Wei Zhao
  2018-01-04  7:46       ` [PATCH v4 1/2] net/e1000: " Wei Zhao
@ 2018-01-04  7:46       ` Wei Zhao
  2018-01-05  6:01         ` Dai, Wei
  2018-01-09  6:20       ` [PATCH v5 0/2] " Wei Zhao
  2 siblings, 1 reply; 28+ messages in thread
From: Wei Zhao @ 2018-01-04  7:46 UTC (permalink / raw)
  To: dev; +Cc: wei.dai, Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move ixgbe existing RSS to rte_flow.
The old RSS configuration is still reserved.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
---
 doc/guides/rel_notes/release_18_02.rst |   6 +-
 drivers/net/ixgbe/ixgbe_ethdev.c       |  13 +++
 drivers/net/ixgbe/ixgbe_ethdev.h       |  10 ++
 drivers/net/ixgbe/ixgbe_flow.c         | 165 +++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_rxtx.c         |  65 +++++++++++++
 5 files changed, 256 insertions(+), 3 deletions(-)

diff --git a/doc/guides/rel_notes/release_18_02.rst b/doc/guides/rel_notes/release_18_02.rst
index 1b91508..4051d8b 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -41,11 +41,11 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
-* **Added the igb ethernet driver to support RSS with flow API.**
+* **Added the igb and ixgbe ethernet driver to support RSS with flow API.**
 
   Rte_flow actually defined to include RSS, but till now, RSS is out of
-  rte_flow. This patch is to support igb NIC with existing RSS configuration
-  using rte_flow API.
+  rte_flow. This patch is to support igb and ixgbe NIC with existing RSS
+  configuration using rte_flow API.
 
 
 API Changes
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index ff19a56..4960650 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -8339,6 +8339,18 @@ ixgbe_l2_tn_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+ixgbe_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		ixgbe_config_rss_filter(dev,
+			&filter_info->rss_info, TRUE);
+}
+
 static int
 ixgbe_filter_restore(struct rte_eth_dev *dev)
 {
@@ -8347,6 +8359,7 @@ ixgbe_filter_restore(struct rte_eth_dev *dev)
 	ixgbe_syn_filter_restore(dev);
 	ixgbe_fdir_filter_restore(dev);
 	ixgbe_l2_tn_filter_restore(dev);
+	ixgbe_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 51ddcfd..4af79b4 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -224,6 +224,12 @@ struct ixgbe_hw_fdir_info {
 	bool mask_added; /* If already got mask from consistent filter */
 };
 
+struct ixgbe_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IXGBE_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /* structure for interrupt relative data */
 struct ixgbe_interrupt {
 	uint32_t flags;
@@ -340,6 +346,8 @@ struct ixgbe_filter_info {
 	struct ixgbe_5tuple_filter_list fivetuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct ixgbe_rte_flow_rss_conf rss_info;
 };
 
 struct ixgbe_l2_tn_key {
@@ -719,6 +727,8 @@ void ixgbe_tm_conf_init(struct rte_eth_dev *dev);
 void ixgbe_tm_conf_uninit(struct rte_eth_dev *dev);
 int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev, uint16_t queue_idx,
 			       uint16_t tx_rate);
+int ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add);
 
 static inline int
 ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info,
diff --git a/drivers/net/ixgbe/ixgbe_flow.c b/drivers/net/ixgbe/ixgbe_flow.c
index 19c2d47..8f964cf 100644
--- a/drivers/net/ixgbe/ixgbe_flow.c
+++ b/drivers/net/ixgbe/ixgbe_flow.c
@@ -103,6 +103,11 @@ struct ixgbe_eth_l2_tunnel_conf_ele {
 	TAILQ_ENTRY(ixgbe_eth_l2_tunnel_conf_ele) entries;
 	struct rte_eth_l2_tunnel_conf filter_info;
 };
+/* rss filter list structure */
+struct ixgbe_rss_conf_ele {
+	TAILQ_ENTRY(ixgbe_rss_conf_ele) entries;
+	struct ixgbe_rte_flow_rss_conf filter_info;
+};
 /* ixgbe_flow memory list structure */
 struct ixgbe_flow_mem {
 	TAILQ_ENTRY(ixgbe_flow_mem) entries;
@@ -114,6 +119,7 @@ TAILQ_HEAD(ixgbe_ethertype_filter_list, ixgbe_ethertype_filter_ele);
 TAILQ_HEAD(ixgbe_syn_filter_list, ixgbe_eth_syn_filter_ele);
 TAILQ_HEAD(ixgbe_fdir_rule_filter_list, ixgbe_fdir_rule_ele);
 TAILQ_HEAD(ixgbe_l2_tunnel_filter_list, ixgbe_eth_l2_tunnel_conf_ele);
+TAILQ_HEAD(ixgbe_rss_filter_list, ixgbe_rss_conf_ele);
 TAILQ_HEAD(ixgbe_flow_mem_list, ixgbe_flow_mem);
 
 static struct ixgbe_ntuple_filter_list filter_ntuple_list;
@@ -121,6 +127,7 @@ static struct ixgbe_ethertype_filter_list filter_ethertype_list;
 static struct ixgbe_syn_filter_list filter_syn_list;
 static struct ixgbe_fdir_rule_filter_list filter_fdir_list;
 static struct ixgbe_l2_tunnel_filter_list filter_l2_tunnel_list;
+static struct ixgbe_rss_filter_list filter_rss_list;
 static struct ixgbe_flow_mem_list ixgbe_flow_list;
 
 /**
@@ -2700,6 +2707,109 @@ ixgbe_parse_fdir_filter(struct rte_eth_dev *dev,
 	return ret;
 }
 
+static int
+ixgbe_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct ixgbe_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	act = next_no_void_action(actions, NULL);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	act = next_no_void_action(actions, act);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
+/* remove the rss filter */
+static void
+ixgbe_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		ixgbe_config_rss_filter(dev, &filter_info->rss_info, FALSE);
+}
+
 void
 ixgbe_filterlist_init(void)
 {
@@ -2708,6 +2818,7 @@ ixgbe_filterlist_init(void)
 	TAILQ_INIT(&filter_syn_list);
 	TAILQ_INIT(&filter_fdir_list);
 	TAILQ_INIT(&filter_l2_tunnel_list);
+	TAILQ_INIT(&filter_rss_list);
 	TAILQ_INIT(&ixgbe_flow_list);
 }
 
@@ -2720,6 +2831,7 @@ ixgbe_filterlist_flush(void)
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	while ((ntuple_filter_ptr = TAILQ_FIRST(&filter_ntuple_list))) {
 		TAILQ_REMOVE(&filter_ntuple_list,
@@ -2756,6 +2868,13 @@ ixgbe_filterlist_flush(void)
 		rte_free(fdir_rule_ptr);
 	}
 
+	while ((rss_filter_ptr = TAILQ_FIRST(&filter_rss_list))) {
+		TAILQ_REMOVE(&filter_rss_list,
+				 rss_filter_ptr,
+				 entries);
+		rte_free(rss_filter_ptr);
+	}
+
 	while ((ixgbe_flow_mem_ptr = TAILQ_FIRST(&ixgbe_flow_list))) {
 		TAILQ_REMOVE(&ixgbe_flow_list,
 				 ixgbe_flow_mem_ptr,
@@ -2786,12 +2905,14 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct ixgbe_ntuple_filter_ele *ntuple_filter_ptr;
 	struct ixgbe_ethertype_filter_ele *ethertype_filter_ptr;
 	struct ixgbe_eth_syn_filter_ele *syn_filter_ptr;
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	uint8_t first_mask = FALSE;
 
@@ -2992,6 +3113,29 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = ixgbe_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("ixgbe_rss_filter",
+				sizeof(struct ixgbe_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&ixgbe_flow_list,
 		ixgbe_flow_mem_ptr, entries);
@@ -3020,6 +3164,7 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_fdir_rule fdir_rule;
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -3049,6 +3194,12 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	memset(&l2_tn_filter, 0, sizeof(struct rte_eth_l2_tunnel_conf));
 	ret = ixgbe_parse_l2_tn_filter(dev, attr, pattern,
 				actions, &l2_tn_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -3075,6 +3226,7 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -3143,6 +3295,17 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(l2_tn_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct ixgbe_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = ixgbe_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -3194,6 +3357,8 @@ ixgbe_flow_flush(struct rte_eth_dev *dev,
 		return ret;
 	}
 
+	ixgbe_clear_rss_filter(dev);
+
 	ixgbe_filterlist_flush();
 
 	return 0;
diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index 9bc8462..4b38247 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -5550,6 +5550,71 @@ ixgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
 	}
 }
 
+int
+ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add)
+{
+	struct ixgbe_hw *hw;
+	uint32_t reta;
+	uint16_t i;
+	uint16_t j;
+	uint16_t sp_reta_size;
+	uint32_t reta_reg;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	PMD_INIT_FUNC_TRACE();
+	hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct ixgbe_rte_flow_rss_conf)) == 0) {
+			ixgbe_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+	/* Fill in redirection table
+	 * The byte-swap is needed because NIC registers are in
+	 * little-endian order.
+	 */
+	reta = 0;
+	for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
+		reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
+
+		if (j == conf->num)
+			j = 0;
+		reta = (reta << 8) | conf->queue[j];
+		if ((i & 3) == 3)
+			IXGBE_WRITE_REG(hw, reta_reg,
+					rte_bswap32(reta));
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
+		ixgbe_rss_disable(dev);
+		return -EINVAL;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	ixgbe_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct ixgbe_rte_flow_rss_conf));
+
+	return 0;
+}
+
 /* Stubs needed for linkage when CONFIG_RTE_IXGBE_INC_VECTOR is set to 'n' */
 int __attribute__((weak))
 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH v3 1/2] net/e1000: move RSS to flow API
  2017-12-21  3:11           ` Zhang, Helin
@ 2018-01-04  8:48             ` Zhao1, Wei
  0 siblings, 0 replies; 28+ messages in thread
From: Zhao1, Wei @ 2018-01-04  8:48 UTC (permalink / raw)
  To: Zhang, Helin, Dai, Wei, dev

Hi, henlin


> -----Original Message-----
> From: Zhang, Helin
> Sent: Thursday, December 21, 2017 11:11 AM
> To: Zhao1, Wei <wei.zhao1@intel.com>; Dai, Wei <wei.dai@intel.com>;
> dev@dpdk.org
> Subject: RE: [dpdk-dev] [PATCH v3 1/2] net/e1000: move RSS to flow API
> 
> 
> 
> > -----Original Message-----
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Zhao1, Wei
> > Sent: Friday, December 8, 2017 10:28 AM
> > To: Dai, Wei; dev@dpdk.org
> > Subject: Re: [dpdk-dev] [PATCH v3 1/2] net/e1000: move RSS to flow API
> >
> > Hi, daiwei
> > 	I  build the code with ICC for second time just now, it can pass
> > build and there is no build error.
> > It seems the icc report is not credible.
> >
> >
> > > -----Original Message-----
> > > From: Dai, Wei
> > > Sent: Thursday, December 7, 2017 5:19 PM
> > > To: Zhao1, Wei <wei.zhao1@intel.com>; dev@dpdk.org
> > > Cc: Zhao1, Wei <wei.zhao1@intel.com>
> > > Subject: RE: [dpdk-dev] [PATCH v3 1/2] net/e1000: move RSS to flow
> > > API
> > >
> > > Hi, Zhao Wei
> > > Please correct build error show in http://dpdk.org/ml/archives/test-
> > > report/2017-November/035129.html
> > >
> > >
> > > > -----Original Message-----
> > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Wei Zhao
> > > > Sent: Friday, November 24, 2017 4:05 PM
> > > > To: dev@dpdk.org
> > > > Cc: Zhao1, Wei <wei.zhao1@intel.com>
> > > > Subject: [dpdk-dev] [PATCH v3 1/2] net/e1000: move RSS to flow API
> > > >
> > > > Rte_flow actually defined to include RSS, but till now, RSS is out
> > > > of
> > rte_flow.
> > > > This patch is to move igb existing RSS to rte_flow.
> > > >
> > > > Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
> 
> I think Wei Dai is right, please double check the error reported, and get that
> fixed.

Yes
Thank you.
I have commit a version v4.

> 
> Thanks,
> Helin

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v3 2/2] net/ixgbe: move RSS to flow API
  2017-12-21  3:11           ` Zhang, Helin
@ 2018-01-04  8:51             ` Zhao1, Wei
  0 siblings, 0 replies; 28+ messages in thread
From: Zhao1, Wei @ 2018-01-04  8:51 UTC (permalink / raw)
  To: Zhang, Helin, Dai, Wei, dev

The same,  a new v4 commit to DPDK.org.


> -----Original Message-----
> From: Zhang, Helin
> Sent: Thursday, December 21, 2017 11:12 AM
> To: Zhao1, Wei <wei.zhao1@intel.com>; Dai, Wei <wei.dai@intel.com>;
> dev@dpdk.org
> Subject: RE: [dpdk-dev] [PATCH v3 2/2] net/ixgbe: move RSS to flow API
> 
> 
> 
> > -----Original Message-----
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Zhao1, Wei
> > Sent: Friday, December 8, 2017 10:28 AM
> > To: Dai, Wei; dev@dpdk.org
> > Subject: Re: [dpdk-dev] [PATCH v3 2/2] net/ixgbe: move RSS to flow API
> >
> > Hi, daiwei
> > 	I  build the code with ICC for second time, it can pass build and
> > there is no build error.
> > It seems the icc report is not credible.
> >
> > > -----Original Message-----
> > > From: Dai, Wei
> > > Sent: Thursday, December 7, 2017 5:20 PM
> > > To: Zhao1, Wei <wei.zhao1@intel.com>; dev@dpdk.org
> > > Cc: Zhao1, Wei <wei.zhao1@intel.com>
> > > Subject: RE: [dpdk-dev] [PATCH v3 2/2] net/ixgbe: move RSS to flow
> > > API
> > >
> > > Hi, Zhao Wei
> > > Please correct build error show in http://dpdk.org/ml/archives/test-
> > > report/2017-November/035130.html
> > >
> > > > -----Original Message-----
> > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Wei Zhao
> > > > Sent: Friday, November 24, 2017 4:05 PM
> > > > To: dev@dpdk.org
> > > > Cc: Zhao1, Wei <wei.zhao1@intel.com>
> > > > Subject: [dpdk-dev] [PATCH v3 2/2] net/ixgbe: move RSS to flow API
> > > >
> > > > Rte_flow actually defined to include RSS, but till now, RSS is out
> > > > of
> > rte_flow.
> > > > This patch is to move ixgbe existing RSS to rte_flow.
> > > >
> > > > Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
> I think Wei Dai is right, please double check the error reported, and get that
> fixed.
> 
> Thanks,
> Helin

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 2/2] net/ixgbe: move RSS to flow API
  2018-01-04  7:46       ` [PATCH v4 2/2] net/ixgbe: " Wei Zhao
@ 2018-01-05  6:01         ` Dai, Wei
  0 siblings, 0 replies; 28+ messages in thread
From: Dai, Wei @ 2018-01-05  6:01 UTC (permalink / raw)
  To: Zhao1, Wei, dev



> -----Original Message-----
> From: Zhao1, Wei
> Sent: Thursday, January 4, 2018 3:46 PM
> To: dev@dpdk.org
> Cc: Dai, Wei <wei.dai@intel.com>; Zhao1, Wei <wei.zhao1@intel.com>
> Subject: [PATCH v4 2/2] net/ixgbe: move RSS to flow API
> 
> Rte_flow actually defined to include RSS, but till now, RSS is out of rte_flow.
> This patch is to move ixgbe existing RSS to rte_flow.
> The old RSS configuration is still reserved.
> 
> Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
Acked-by: Wei Dai <wei.dai@intel.com>

> ---
>  doc/guides/rel_notes/release_18_02.rst |   6 +-
>  drivers/net/ixgbe/ixgbe_ethdev.c       |  13 +++
>  drivers/net/ixgbe/ixgbe_ethdev.h       |  10 ++
>  drivers/net/ixgbe/ixgbe_flow.c         | 165
> +++++++++++++++++++++++++++++++++
>  drivers/net/ixgbe/ixgbe_rxtx.c         |  65 +++++++++++++
>  5 files changed, 256 insertions(+), 3 deletions(-)
> 

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v4 1/2] net/e1000: move RSS to flow API
  2018-01-04  7:46       ` [PATCH v4 1/2] net/e1000: " Wei Zhao
@ 2018-01-05  6:05         ` Dai, Wei
  0 siblings, 0 replies; 28+ messages in thread
From: Dai, Wei @ 2018-01-05  6:05 UTC (permalink / raw)
  To: Zhao1, Wei, dev

> -----Original Message-----
> From: Zhao1, Wei
> Sent: Thursday, January 4, 2018 3:46 PM
> To: dev@dpdk.org
> Cc: Dai, Wei <wei.dai@intel.com>; Zhao1, Wei <wei.zhao1@intel.com>
> Subject: [PATCH v4 1/2] net/e1000: move RSS to flow API
> 
> Rte_flow actually defined to include RSS, but till now, RSS is out of rte_flow.
> This patch is to move igb existing RSS to rte_flow.
> The old RSS configuration is still reserved.
> 
> Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
Acked-by: Wei Dai <wei.dai@intel.com>
> ---
>  doc/guides/rel_notes/release_18_02.rst |   6 ++
>  drivers/net/e1000/e1000_ethdev.h       |  20 +++++
>  drivers/net/e1000/igb_ethdev.c         |  17 ++++
>  drivers/net/e1000/igb_flow.c           | 160
> +++++++++++++++++++++++++++++++++
>  drivers/net/e1000/igb_rxtx.c           |  61 +++++++++++++
>  5 files changed, 264 insertions(+)
> 

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v5 0/2] move RSS to flow API
  2018-01-04  7:46     ` [PATCH v4 0/2] " Wei Zhao
  2018-01-04  7:46       ` [PATCH v4 1/2] net/e1000: " Wei Zhao
  2018-01-04  7:46       ` [PATCH v4 2/2] net/ixgbe: " Wei Zhao
@ 2018-01-09  6:20       ` Wei Zhao
  2018-01-09  6:20         ` [PATCH v5 1/2] net/e1000: " Wei Zhao
                           ` (2 more replies)
  2 siblings, 3 replies; 28+ messages in thread
From: Wei Zhao @ 2018-01-09  6:20 UTC (permalink / raw)
  To: dev; +Cc: helin.zhang

The patches mainly finish following functions:
1) igb move RSS to flow API
2) ixgbe move RSS to flow API

v2:
-fix bug for RSS flush code.
-fix patch check warning.

v3:
-fix bug for ixgbe rss restore.

v4:
-fix build warning and add release notes comment.

v5:
-rebase patch set.

Wei Zhao (2):
  net/e1000: move RSS to flow API
  net/ixgbe: move RSS to flow API

 doc/guides/rel_notes/release_18_02.rst |   6 ++
 drivers/net/e1000/e1000_ethdev.h       |  20 ++++
 drivers/net/e1000/igb_ethdev.c         |  17 ++++
 drivers/net/e1000/igb_flow.c           | 160 ++++++++++++++++++++++++++++++++
 drivers/net/e1000/igb_rxtx.c           |  61 ++++++++++++
 drivers/net/ixgbe/ixgbe_ethdev.c       |  13 +++
 drivers/net/ixgbe/ixgbe_ethdev.h       |  10 ++
 drivers/net/ixgbe/ixgbe_flow.c         | 165 +++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_rxtx.c         |  65 +++++++++++++
 9 files changed, 517 insertions(+)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v5 1/2] net/e1000: move RSS to flow API
  2018-01-09  6:20       ` [PATCH v5 0/2] " Wei Zhao
@ 2018-01-09  6:20         ` Wei Zhao
  2018-01-09  6:20         ` [PATCH v5 2/2] net/ixgbe: " Wei Zhao
  2018-01-09  6:44         ` [PATCH v6 0/2] " Wei Zhao
  2 siblings, 0 replies; 28+ messages in thread
From: Wei Zhao @ 2018-01-09  6:20 UTC (permalink / raw)
  To: dev; +Cc: helin.zhang, Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move igb existing RSS to rte_flow.
The old RSS configuration is still reserved.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
Acked-by: Wei Dai <wei.dai@intel.com>
---
 doc/guides/rel_notes/release_18_02.rst |   6 ++
 drivers/net/e1000/e1000_ethdev.h       |  20 +++++
 drivers/net/e1000/igb_ethdev.c         |  17 ++++
 drivers/net/e1000/igb_flow.c           | 160 +++++++++++++++++++++++++++++++++
 drivers/net/e1000/igb_rxtx.c           |  61 +++++++++++++
 5 files changed, 264 insertions(+)

diff --git a/doc/guides/rel_notes/release_18_02.rst b/doc/guides/rel_notes/release_18_02.rst
index 621b8f5..8bccf25 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -47,6 +47,12 @@ New Features
   users. According to the device configuration, it will setup TX->RX loopback
   link or not.
 
+* **Added the igb ethernet driver to support RSS with flow API.**
+
+  Rte_flow actually defined to include RSS, but till now, RSS is out of
+  rte_flow. This patch is to support igb NIC with existing RSS configuration
+  using rte_flow API.
+
 API Changes
 -----------
 
diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index efb8d9e..23b089c 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -228,6 +228,12 @@ struct igb_ethertype_filter {
 	uint32_t etqf;
 };
 
+struct igb_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IGB_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /*
  * Structure to store filters'info.
  */
@@ -245,6 +251,8 @@ struct e1000_filter_info {
 	struct e1000_2tuple_filter_list twotuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct igb_rte_flow_rss_conf rss_info;
 };
 
 /*
@@ -313,6 +321,12 @@ struct igb_flex_filter_ele {
 	struct rte_eth_flex_filter filter_info;
 };
 
+/* rss filter  list structure */
+struct igb_rss_conf_ele {
+	TAILQ_ENTRY(igb_rss_conf_ele) entries;
+	struct igb_rte_flow_rss_conf filter_info;
+};
+
 /* igb_flow memory list structure */
 struct igb_flow_mem {
 	TAILQ_ENTRY(igb_flow_mem) entries;
@@ -328,6 +342,8 @@ TAILQ_HEAD(igb_syn_filter_list, igb_eth_syn_filter_ele);
 struct igb_syn_filter_list igb_filter_syn_list;
 TAILQ_HEAD(igb_flex_filter_list, igb_flex_filter_ele);
 struct igb_flex_filter_list igb_filter_flex_list;
+TAILQ_HEAD(igb_rss_filter_list, igb_rss_conf_ele);
+struct igb_rss_filter_list igb_filter_rss_list;
 TAILQ_HEAD(igb_flow_mem_list, igb_flow_mem);
 struct igb_flow_mem_list igb_flow_list;
 
@@ -471,4 +487,8 @@ int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
 int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
 			struct rte_eth_flex_filter *filter,
 			bool add);
+int igb_config_rss_filter(struct rte_eth_dev *dev,
+			struct igb_rte_flow_rss_conf *conf,
+			bool add);
+
 #endif /* _E1000_ETHDEV_H_ */
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index 6c10705..a80d591 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -919,6 +919,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 	TAILQ_INIT(&igb_filter_ethertype_list);
 	TAILQ_INIT(&igb_filter_syn_list);
 	TAILQ_INIT(&igb_filter_flex_list);
+	TAILQ_INIT(&igb_filter_rss_list);
 	TAILQ_INIT(&igb_flow_list);
 
 	return 0;
@@ -978,6 +979,10 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 	memset(filter_info->ethertype_filters, 0,
 		E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
 
+	/* clear the rss filter info */
+	memset(&filter_info->rss_info, 0,
+		sizeof(struct igb_rte_flow_rss_conf));
+
 	/* remove all ntuple filters of the device */
 	igb_ntuple_filter_uninit(eth_dev);
 
@@ -5599,6 +5604,17 @@ igb_flex_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+igb_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		igb_config_rss_filter(dev, &filter_info->rss_info, TRUE);
+}
+
 /* restore all types filter */
 static int
 igb_filter_restore(struct rte_eth_dev *dev)
@@ -5607,6 +5623,7 @@ igb_filter_restore(struct rte_eth_dev *dev)
 	igb_ethertype_filter_restore(dev);
 	igb_syn_filter_restore(dev);
 	igb_flex_filter_restore(dev);
+	igb_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/e1000/igb_flow.c b/drivers/net/e1000/igb_flow.c
index 70cafea..b560f16 100644
--- a/drivers/net/e1000/igb_flow.c
+++ b/drivers/net/e1000/igb_flow.c
@@ -1266,6 +1266,101 @@ igb_parse_flex_filter(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+igb_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct igb_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n, index;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	index = 0;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IGB_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	index++;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
 /**
  * Create a flow rule.
  * Theorically one rule can match more than one filters.
@@ -1284,11 +1379,13 @@ igb_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct igb_ntuple_filter_ele *ntuple_filter_ptr;
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 
 	flow = rte_zmalloc("igb_rte_flow", sizeof(struct rte_flow), 0);
@@ -1390,6 +1487,29 @@ igb_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = igb_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("igb_rss_filter",
+				sizeof(struct igb_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct igb_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&igb_flow_list,
 		igb_flow_mem_ptr, entries);
@@ -1417,6 +1537,7 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -1440,6 +1561,12 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	memset(&flex_filter, 0, sizeof(struct rte_eth_flex_filter));
 	ret = igb_parse_flex_filter(dev, attr, pattern,
 				actions, &flex_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -1458,6 +1585,7 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -1504,6 +1632,17 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(flex_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct igb_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = igb_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -1592,6 +1731,17 @@ igb_clear_all_flex_filter(struct rte_eth_dev *dev)
 		igb_remove_flex_filter(dev, flex_filter);
 }
 
+/* remove the rss filter */
+static void
+igb_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter->rss_info.num)
+		igb_config_rss_filter(dev, &filter->rss_info, FALSE);
+}
+
 void
 igb_filterlist_flush(struct rte_eth_dev *dev)
 {
@@ -1599,6 +1749,7 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele  *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 	enum rte_filter_type filter_type;
 	struct rte_flow *pmd_flow;
@@ -1641,6 +1792,14 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 						flex_filter_ptr, entries);
 				rte_free(flex_filter_ptr);
 				break;
+			case RTE_ETH_FILTER_HASH:
+				rss_filter_ptr =
+					(struct igb_rss_conf_ele *)
+						pmd_flow->rule;
+				TAILQ_REMOVE(&igb_filter_rss_list,
+						rss_filter_ptr, entries);
+				rte_free(rss_filter_ptr);
+				break;
 			default:
 				PMD_DRV_LOG(WARNING, "Filter type"
 					"(%d) not supported", filter_type);
@@ -1664,6 +1823,7 @@ igb_flow_flush(struct rte_eth_dev *dev,
 	igb_clear_all_ethertype_filter(dev);
 	igb_clear_syn_filter(dev);
 	igb_clear_all_flex_filter(dev);
+	igb_clear_rss_filter(dev);
 	igb_filterlist_flush(dev);
 
 	return 0;
diff --git a/drivers/net/e1000/igb_rxtx.c b/drivers/net/e1000/igb_rxtx.c
index 19e5a80..a2abc75 100644
--- a/drivers/net/e1000/igb_rxtx.c
+++ b/drivers/net/e1000/igb_rxtx.c
@@ -2757,3 +2757,64 @@ igb_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 	qinfo->conf.tx_thresh.hthresh = txq->hthresh;
 	qinfo->conf.tx_thresh.wthresh = txq->wthresh;
 }
+
+int
+igb_config_rss_filter(struct rte_eth_dev *dev,
+		struct igb_rte_flow_rss_conf *conf, bool add)
+{
+	uint32_t shift;
+	uint16_t i, j;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct igb_rte_flow_rss_conf)) == 0) {
+			igb_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct igb_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+
+	/* Fill in redirection table. */
+	shift = (hw->mac.type == e1000_82575) ? 6 : 0;
+	for (i = 0, j = 0; i < 128; i++, j++) {
+		union e1000_reta {
+			uint32_t dword;
+			uint8_t  bytes[4];
+		} reta;
+		uint8_t q_idx;
+
+		q_idx = conf->queue[j];
+		if (j == conf->num)
+			j = 0;
+		reta.bytes[i & 3] = (uint8_t)(q_idx << shift);
+		if ((i & 3) == 3)
+			E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
+		igb_rss_disable(dev);
+		return 0;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	igb_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct igb_rte_flow_rss_conf));
+
+	return 0;
+}
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v5 2/2] net/ixgbe: move RSS to flow API
  2018-01-09  6:20       ` [PATCH v5 0/2] " Wei Zhao
  2018-01-09  6:20         ` [PATCH v5 1/2] net/e1000: " Wei Zhao
@ 2018-01-09  6:20         ` Wei Zhao
  2018-01-09  6:44         ` [PATCH v6 0/2] " Wei Zhao
  2 siblings, 0 replies; 28+ messages in thread
From: Wei Zhao @ 2018-01-09  6:20 UTC (permalink / raw)
  To: dev; +Cc: helin.zhang, Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move ixgbe existing RSS to rte_flow.
The old RSS configuration is still reserved.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
Acked-by: Wei Dai <wei.dai@intel.com>
---
 doc/guides/rel_notes/release_18_02.rst |   6 +-
 drivers/net/ixgbe/ixgbe_ethdev.c       |  13 +++
 drivers/net/ixgbe/ixgbe_ethdev.h       |  10 ++
 drivers/net/ixgbe/ixgbe_flow.c         | 165 +++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_rxtx.c         |  65 +++++++++++++
 5 files changed, 256 insertions(+), 3 deletions(-)

diff --git a/doc/guides/rel_notes/release_18_02.rst b/doc/guides/rel_notes/release_18_02.rst
index 8bccf25..347a6b8 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -47,11 +47,11 @@ New Features
   users. According to the device configuration, it will setup TX->RX loopback
   link or not.
 
-* **Added the igb ethernet driver to support RSS with flow API.**
+* **Added the igb and ixgbe ethernet driver to support RSS with flow API.**
 
   Rte_flow actually defined to include RSS, but till now, RSS is out of
-  rte_flow. This patch is to support igb NIC with existing RSS configuration
-  using rte_flow API.
+  rte_flow. This patch is to support igb and ixgbe NIC with existing RSS
+  configuration using rte_flow API.
 
 API Changes
 -----------
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 43e0132..d632885 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -8310,6 +8310,18 @@ ixgbe_l2_tn_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+ixgbe_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		ixgbe_config_rss_filter(dev,
+			&filter_info->rss_info, TRUE);
+}
+
 static int
 ixgbe_filter_restore(struct rte_eth_dev *dev)
 {
@@ -8318,6 +8330,7 @@ ixgbe_filter_restore(struct rte_eth_dev *dev)
 	ixgbe_syn_filter_restore(dev);
 	ixgbe_fdir_filter_restore(dev);
 	ixgbe_l2_tn_filter_restore(dev);
+	ixgbe_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 1db29bd..c56d652 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -195,6 +195,12 @@ struct ixgbe_hw_fdir_info {
 	bool mask_added; /* If already got mask from consistent filter */
 };
 
+struct ixgbe_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IXGBE_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /* structure for interrupt relative data */
 struct ixgbe_interrupt {
 	uint32_t flags;
@@ -311,6 +317,8 @@ struct ixgbe_filter_info {
 	struct ixgbe_5tuple_filter_list fivetuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct ixgbe_rte_flow_rss_conf rss_info;
 };
 
 struct ixgbe_l2_tn_key {
@@ -690,6 +698,8 @@ void ixgbe_tm_conf_init(struct rte_eth_dev *dev);
 void ixgbe_tm_conf_uninit(struct rte_eth_dev *dev);
 int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev, uint16_t queue_idx,
 			       uint16_t tx_rate);
+int ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add);
 
 static inline int
 ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info,
diff --git a/drivers/net/ixgbe/ixgbe_flow.c b/drivers/net/ixgbe/ixgbe_flow.c
index f31aebd..7115a71 100644
--- a/drivers/net/ixgbe/ixgbe_flow.c
+++ b/drivers/net/ixgbe/ixgbe_flow.c
@@ -74,6 +74,11 @@ struct ixgbe_eth_l2_tunnel_conf_ele {
 	TAILQ_ENTRY(ixgbe_eth_l2_tunnel_conf_ele) entries;
 	struct rte_eth_l2_tunnel_conf filter_info;
 };
+/* rss filter list structure */
+struct ixgbe_rss_conf_ele {
+	TAILQ_ENTRY(ixgbe_rss_conf_ele) entries;
+	struct ixgbe_rte_flow_rss_conf filter_info;
+};
 /* ixgbe_flow memory list structure */
 struct ixgbe_flow_mem {
 	TAILQ_ENTRY(ixgbe_flow_mem) entries;
@@ -85,6 +90,7 @@ TAILQ_HEAD(ixgbe_ethertype_filter_list, ixgbe_ethertype_filter_ele);
 TAILQ_HEAD(ixgbe_syn_filter_list, ixgbe_eth_syn_filter_ele);
 TAILQ_HEAD(ixgbe_fdir_rule_filter_list, ixgbe_fdir_rule_ele);
 TAILQ_HEAD(ixgbe_l2_tunnel_filter_list, ixgbe_eth_l2_tunnel_conf_ele);
+TAILQ_HEAD(ixgbe_rss_filter_list, ixgbe_rss_conf_ele);
 TAILQ_HEAD(ixgbe_flow_mem_list, ixgbe_flow_mem);
 
 static struct ixgbe_ntuple_filter_list filter_ntuple_list;
@@ -92,6 +98,7 @@ static struct ixgbe_ethertype_filter_list filter_ethertype_list;
 static struct ixgbe_syn_filter_list filter_syn_list;
 static struct ixgbe_fdir_rule_filter_list filter_fdir_list;
 static struct ixgbe_l2_tunnel_filter_list filter_l2_tunnel_list;
+static struct ixgbe_rss_filter_list filter_rss_list;
 static struct ixgbe_flow_mem_list ixgbe_flow_list;
 
 /**
@@ -2726,6 +2733,109 @@ ixgbe_parse_fdir_filter(struct rte_eth_dev *dev,
 	return ret;
 }
 
+static int
+ixgbe_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct ixgbe_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	act = next_no_void_action(actions, NULL);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	act = next_no_void_action(actions, act);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
+/* remove the rss filter */
+static void
+ixgbe_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		ixgbe_config_rss_filter(dev, &filter_info->rss_info, FALSE);
+}
+
 void
 ixgbe_filterlist_init(void)
 {
@@ -2734,6 +2844,7 @@ ixgbe_filterlist_init(void)
 	TAILQ_INIT(&filter_syn_list);
 	TAILQ_INIT(&filter_fdir_list);
 	TAILQ_INIT(&filter_l2_tunnel_list);
+	TAILQ_INIT(&filter_rss_list);
 	TAILQ_INIT(&ixgbe_flow_list);
 }
 
@@ -2746,6 +2857,7 @@ ixgbe_filterlist_flush(void)
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	while ((ntuple_filter_ptr = TAILQ_FIRST(&filter_ntuple_list))) {
 		TAILQ_REMOVE(&filter_ntuple_list,
@@ -2782,6 +2894,13 @@ ixgbe_filterlist_flush(void)
 		rte_free(fdir_rule_ptr);
 	}
 
+	while ((rss_filter_ptr = TAILQ_FIRST(&filter_rss_list))) {
+		TAILQ_REMOVE(&filter_rss_list,
+				 rss_filter_ptr,
+				 entries);
+		rte_free(rss_filter_ptr);
+	}
+
 	while ((ixgbe_flow_mem_ptr = TAILQ_FIRST(&ixgbe_flow_list))) {
 		TAILQ_REMOVE(&ixgbe_flow_list,
 				 ixgbe_flow_mem_ptr,
@@ -2812,12 +2931,14 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct ixgbe_ntuple_filter_ele *ntuple_filter_ptr;
 	struct ixgbe_ethertype_filter_ele *ethertype_filter_ptr;
 	struct ixgbe_eth_syn_filter_ele *syn_filter_ptr;
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	uint8_t first_mask = FALSE;
 
@@ -3018,6 +3139,29 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = ixgbe_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("ixgbe_rss_filter",
+				sizeof(struct ixgbe_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&ixgbe_flow_list,
 		ixgbe_flow_mem_ptr, entries);
@@ -3046,6 +3190,7 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_fdir_rule fdir_rule;
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -3075,6 +3220,12 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	memset(&l2_tn_filter, 0, sizeof(struct rte_eth_l2_tunnel_conf));
 	ret = ixgbe_parse_l2_tn_filter(dev, attr, pattern,
 				actions, &l2_tn_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -3101,6 +3252,7 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -3169,6 +3321,17 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(l2_tn_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct ixgbe_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = ixgbe_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -3220,6 +3383,8 @@ ixgbe_flow_flush(struct rte_eth_dev *dev,
 		return ret;
 	}
 
+	ixgbe_clear_rss_filter(dev);
+
 	ixgbe_filterlist_flush();
 
 	return 0;
diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index 9bc8462..4b38247 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -5550,6 +5550,71 @@ ixgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
 	}
 }
 
+int
+ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add)
+{
+	struct ixgbe_hw *hw;
+	uint32_t reta;
+	uint16_t i;
+	uint16_t j;
+	uint16_t sp_reta_size;
+	uint32_t reta_reg;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	PMD_INIT_FUNC_TRACE();
+	hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct ixgbe_rte_flow_rss_conf)) == 0) {
+			ixgbe_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+	/* Fill in redirection table
+	 * The byte-swap is needed because NIC registers are in
+	 * little-endian order.
+	 */
+	reta = 0;
+	for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
+		reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
+
+		if (j == conf->num)
+			j = 0;
+		reta = (reta << 8) | conf->queue[j];
+		if ((i & 3) == 3)
+			IXGBE_WRITE_REG(hw, reta_reg,
+					rte_bswap32(reta));
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
+		ixgbe_rss_disable(dev);
+		return -EINVAL;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	ixgbe_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct ixgbe_rte_flow_rss_conf));
+
+	return 0;
+}
+
 /* Stubs needed for linkage when CONFIG_RTE_IXGBE_INC_VECTOR is set to 'n' */
 int __attribute__((weak))
 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v6 0/2] move RSS to flow API
  2018-01-09  6:20       ` [PATCH v5 0/2] " Wei Zhao
  2018-01-09  6:20         ` [PATCH v5 1/2] net/e1000: " Wei Zhao
  2018-01-09  6:20         ` [PATCH v5 2/2] net/ixgbe: " Wei Zhao
@ 2018-01-09  6:44         ` Wei Zhao
  2018-01-09  6:44           ` [PATCH v6 1/2] net/e1000: " Wei Zhao
                             ` (2 more replies)
  2 siblings, 3 replies; 28+ messages in thread
From: Wei Zhao @ 2018-01-09  6:44 UTC (permalink / raw)
  To: dev; +Cc: helin.zhang

The patches mainly finish following functions:
1) igb move RSS to flow API
2) ixgbe move RSS to flow API

v2:
-fix bug for RSS flush code.
-fix patch check warning.

v3:
-fix bug for ixgbe rss restore.

v4:
-fix build warning and add release notes comment.

v5:
-rebase patch set.

v6:
-rebase patch set.

wei zhao (2):
  net/e1000: move RSS to flow API
  net/ixgbe: move RSS to flow API

 doc/guides/rel_notes/release_18_02.rst |   6 ++
 drivers/net/e1000/e1000_ethdev.h       |  20 ++++
 drivers/net/e1000/igb_ethdev.c         |  17 ++++
 drivers/net/e1000/igb_flow.c           | 160 ++++++++++++++++++++++++++++++++
 drivers/net/e1000/igb_rxtx.c           |  61 ++++++++++++
 drivers/net/ixgbe/ixgbe_ethdev.c       |  13 +++
 drivers/net/ixgbe/ixgbe_ethdev.h       |  10 ++
 drivers/net/ixgbe/ixgbe_flow.c         | 165 +++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_rxtx.c         |  65 +++++++++++++
 9 files changed, 517 insertions(+)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v6 1/2] net/e1000: move RSS to flow API
  2018-01-09  6:44         ` [PATCH v6 0/2] " Wei Zhao
@ 2018-01-09  6:44           ` Wei Zhao
  2018-01-09  6:44           ` [PATCH v6 2/2] net/ixgbe: " Wei Zhao
  2018-01-09  7:11           ` [PATCH v6 0/2] " Zhang, Helin
  2 siblings, 0 replies; 28+ messages in thread
From: Wei Zhao @ 2018-01-09  6:44 UTC (permalink / raw)
  To: dev; +Cc: helin.zhang, Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move igb existing RSS to rte_flow.
The old RSS configuration is still reserved.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
Acked-by: Wei Dai <wei.dai@intel.com>
---
 doc/guides/rel_notes/release_18_02.rst |   6 ++
 drivers/net/e1000/e1000_ethdev.h       |  20 +++++
 drivers/net/e1000/igb_ethdev.c         |  17 ++++
 drivers/net/e1000/igb_flow.c           | 160 +++++++++++++++++++++++++++++++++
 drivers/net/e1000/igb_rxtx.c           |  61 +++++++++++++
 5 files changed, 264 insertions(+)

diff --git a/doc/guides/rel_notes/release_18_02.rst b/doc/guides/rel_notes/release_18_02.rst
index b8e0e5a..e81adc9 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -63,6 +63,12 @@ New Features
   process of set or flush queue region configure. Aslo add a document for
   these new commands. This feature has been implemented in 17.11.
 
+* **Added the igb ethernet driver to support RSS with flow API.**
+
+  Rte_flow actually defined to include RSS, but till now, RSS is out of
+  rte_flow. This patch is to support igb NIC with existing RSS configuration
+  using rte_flow API.
+
 API Changes
 -----------
 
diff --git a/drivers/net/e1000/e1000_ethdev.h b/drivers/net/e1000/e1000_ethdev.h
index efb8d9e..23b089c 100644
--- a/drivers/net/e1000/e1000_ethdev.h
+++ b/drivers/net/e1000/e1000_ethdev.h
@@ -228,6 +228,12 @@ struct igb_ethertype_filter {
 	uint32_t etqf;
 };
 
+struct igb_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IGB_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /*
  * Structure to store filters'info.
  */
@@ -245,6 +251,8 @@ struct e1000_filter_info {
 	struct e1000_2tuple_filter_list twotuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct igb_rte_flow_rss_conf rss_info;
 };
 
 /*
@@ -313,6 +321,12 @@ struct igb_flex_filter_ele {
 	struct rte_eth_flex_filter filter_info;
 };
 
+/* rss filter  list structure */
+struct igb_rss_conf_ele {
+	TAILQ_ENTRY(igb_rss_conf_ele) entries;
+	struct igb_rte_flow_rss_conf filter_info;
+};
+
 /* igb_flow memory list structure */
 struct igb_flow_mem {
 	TAILQ_ENTRY(igb_flow_mem) entries;
@@ -328,6 +342,8 @@ TAILQ_HEAD(igb_syn_filter_list, igb_eth_syn_filter_ele);
 struct igb_syn_filter_list igb_filter_syn_list;
 TAILQ_HEAD(igb_flex_filter_list, igb_flex_filter_ele);
 struct igb_flex_filter_list igb_filter_flex_list;
+TAILQ_HEAD(igb_rss_filter_list, igb_rss_conf_ele);
+struct igb_rss_filter_list igb_filter_rss_list;
 TAILQ_HEAD(igb_flow_mem_list, igb_flow_mem);
 struct igb_flow_mem_list igb_flow_list;
 
@@ -471,4 +487,8 @@ int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
 int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
 			struct rte_eth_flex_filter *filter,
 			bool add);
+int igb_config_rss_filter(struct rte_eth_dev *dev,
+			struct igb_rte_flow_rss_conf *conf,
+			bool add);
+
 #endif /* _E1000_ETHDEV_H_ */
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index 6c10705..a80d591 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -919,6 +919,7 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
 	TAILQ_INIT(&igb_filter_ethertype_list);
 	TAILQ_INIT(&igb_filter_syn_list);
 	TAILQ_INIT(&igb_filter_flex_list);
+	TAILQ_INIT(&igb_filter_rss_list);
 	TAILQ_INIT(&igb_flow_list);
 
 	return 0;
@@ -978,6 +979,10 @@ eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 	memset(filter_info->ethertype_filters, 0,
 		E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
 
+	/* clear the rss filter info */
+	memset(&filter_info->rss_info, 0,
+		sizeof(struct igb_rte_flow_rss_conf));
+
 	/* remove all ntuple filters of the device */
 	igb_ntuple_filter_uninit(eth_dev);
 
@@ -5599,6 +5604,17 @@ igb_flex_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+igb_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		igb_config_rss_filter(dev, &filter_info->rss_info, TRUE);
+}
+
 /* restore all types filter */
 static int
 igb_filter_restore(struct rte_eth_dev *dev)
@@ -5607,6 +5623,7 @@ igb_filter_restore(struct rte_eth_dev *dev)
 	igb_ethertype_filter_restore(dev);
 	igb_syn_filter_restore(dev);
 	igb_flex_filter_restore(dev);
+	igb_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/e1000/igb_flow.c b/drivers/net/e1000/igb_flow.c
index 70cafea..b560f16 100644
--- a/drivers/net/e1000/igb_flow.c
+++ b/drivers/net/e1000/igb_flow.c
@@ -1266,6 +1266,101 @@ igb_parse_flex_filter(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+igb_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct igb_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n, index;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	index = 0;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IGB_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	index++;
+	NEXT_ITEM_OF_ACTION(act, actions, index);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
 /**
  * Create a flow rule.
  * Theorically one rule can match more than one filters.
@@ -1284,11 +1379,13 @@ igb_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct igb_ntuple_filter_ele *ntuple_filter_ptr;
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 
 	flow = rte_zmalloc("igb_rte_flow", sizeof(struct rte_flow), 0);
@@ -1390,6 +1487,29 @@ igb_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = igb_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("igb_rss_filter",
+				sizeof(struct igb_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct igb_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&igb_flow_list,
 		igb_flow_mem_ptr, entries);
@@ -1417,6 +1537,7 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	struct rte_eth_ethertype_filter ethertype_filter;
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_flex_filter flex_filter;
+	struct igb_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -1440,6 +1561,12 @@ igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
 	memset(&flex_filter, 0, sizeof(struct rte_eth_flex_filter));
 	ret = igb_parse_flex_filter(dev, attr, pattern,
 				actions, &flex_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
+	ret = igb_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -1458,6 +1585,7 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
+	struct igb_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -1504,6 +1632,17 @@ igb_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(flex_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct igb_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = igb_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&igb_filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -1592,6 +1731,17 @@ igb_clear_all_flex_filter(struct rte_eth_dev *dev)
 		igb_remove_flex_filter(dev, flex_filter);
 }
 
+/* remove the rss filter */
+static void
+igb_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct e1000_filter_info *filter =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter->rss_info.num)
+		igb_config_rss_filter(dev, &filter->rss_info, FALSE);
+}
+
 void
 igb_filterlist_flush(struct rte_eth_dev *dev)
 {
@@ -1599,6 +1749,7 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 	struct igb_ethertype_filter_ele *ethertype_filter_ptr;
 	struct igb_eth_syn_filter_ele *syn_filter_ptr;
 	struct igb_flex_filter_ele *flex_filter_ptr;
+	struct igb_rss_conf_ele  *rss_filter_ptr;
 	struct igb_flow_mem *igb_flow_mem_ptr;
 	enum rte_filter_type filter_type;
 	struct rte_flow *pmd_flow;
@@ -1641,6 +1792,14 @@ igb_filterlist_flush(struct rte_eth_dev *dev)
 						flex_filter_ptr, entries);
 				rte_free(flex_filter_ptr);
 				break;
+			case RTE_ETH_FILTER_HASH:
+				rss_filter_ptr =
+					(struct igb_rss_conf_ele *)
+						pmd_flow->rule;
+				TAILQ_REMOVE(&igb_filter_rss_list,
+						rss_filter_ptr, entries);
+				rte_free(rss_filter_ptr);
+				break;
 			default:
 				PMD_DRV_LOG(WARNING, "Filter type"
 					"(%d) not supported", filter_type);
@@ -1664,6 +1823,7 @@ igb_flow_flush(struct rte_eth_dev *dev,
 	igb_clear_all_ethertype_filter(dev);
 	igb_clear_syn_filter(dev);
 	igb_clear_all_flex_filter(dev);
+	igb_clear_rss_filter(dev);
 	igb_filterlist_flush(dev);
 
 	return 0;
diff --git a/drivers/net/e1000/igb_rxtx.c b/drivers/net/e1000/igb_rxtx.c
index 19e5a80..a2abc75 100644
--- a/drivers/net/e1000/igb_rxtx.c
+++ b/drivers/net/e1000/igb_rxtx.c
@@ -2757,3 +2757,64 @@ igb_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
 	qinfo->conf.tx_thresh.hthresh = txq->hthresh;
 	qinfo->conf.tx_thresh.wthresh = txq->wthresh;
 }
+
+int
+igb_config_rss_filter(struct rte_eth_dev *dev,
+		struct igb_rte_flow_rss_conf *conf, bool add)
+{
+	uint32_t shift;
+	uint16_t i, j;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct e1000_filter_info *filter_info =
+		E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+	struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct igb_rte_flow_rss_conf)) == 0) {
+			igb_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct igb_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+
+	/* Fill in redirection table. */
+	shift = (hw->mac.type == e1000_82575) ? 6 : 0;
+	for (i = 0, j = 0; i < 128; i++, j++) {
+		union e1000_reta {
+			uint32_t dword;
+			uint8_t  bytes[4];
+		} reta;
+		uint8_t q_idx;
+
+		q_idx = conf->queue[j];
+		if (j == conf->num)
+			j = 0;
+		reta.bytes[i & 3] = (uint8_t)(q_idx << shift);
+		if ((i & 3) == 3)
+			E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
+		igb_rss_disable(dev);
+		return 0;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	igb_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct igb_rte_flow_rss_conf));
+
+	return 0;
+}
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v6 2/2] net/ixgbe: move RSS to flow API
  2018-01-09  6:44         ` [PATCH v6 0/2] " Wei Zhao
  2018-01-09  6:44           ` [PATCH v6 1/2] net/e1000: " Wei Zhao
@ 2018-01-09  6:44           ` Wei Zhao
  2018-01-09  7:11           ` [PATCH v6 0/2] " Zhang, Helin
  2 siblings, 0 replies; 28+ messages in thread
From: Wei Zhao @ 2018-01-09  6:44 UTC (permalink / raw)
  To: dev; +Cc: helin.zhang, Wei Zhao

Rte_flow actually defined to include RSS,
but till now, RSS is out of rte_flow.
This patch is to move ixgbe existing RSS to rte_flow.
The old RSS configuration is still reserved.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
Acked-by: Wei Dai <wei.dai@intel.com>
---
 doc/guides/rel_notes/release_18_02.rst |   6 +-
 drivers/net/ixgbe/ixgbe_ethdev.c       |  13 +++
 drivers/net/ixgbe/ixgbe_ethdev.h       |  10 ++
 drivers/net/ixgbe/ixgbe_flow.c         | 165 +++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_rxtx.c         |  65 +++++++++++++
 5 files changed, 256 insertions(+), 3 deletions(-)

diff --git a/doc/guides/rel_notes/release_18_02.rst b/doc/guides/rel_notes/release_18_02.rst
index e81adc9..f6e8090 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -63,11 +63,11 @@ New Features
   process of set or flush queue region configure. Aslo add a document for
   these new commands. This feature has been implemented in 17.11.
 
-* **Added the igb ethernet driver to support RSS with flow API.**
+* **Added the igb and ixgbe ethernet driver to support RSS with flow API.**
 
   Rte_flow actually defined to include RSS, but till now, RSS is out of
-  rte_flow. This patch is to support igb NIC with existing RSS configuration
-  using rte_flow API.
+  rte_flow. This patch is to support igb and ixgbe NIC with existing RSS
+  configuration using rte_flow API.
 
 API Changes
 -----------
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index 43e0132..d632885 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -8310,6 +8310,18 @@ ixgbe_l2_tn_filter_restore(struct rte_eth_dev *dev)
 	}
 }
 
+/* restore rss filter */
+static inline void
+ixgbe_rss_filter_restore(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		ixgbe_config_rss_filter(dev,
+			&filter_info->rss_info, TRUE);
+}
+
 static int
 ixgbe_filter_restore(struct rte_eth_dev *dev)
 {
@@ -8318,6 +8330,7 @@ ixgbe_filter_restore(struct rte_eth_dev *dev)
 	ixgbe_syn_filter_restore(dev);
 	ixgbe_fdir_filter_restore(dev);
 	ixgbe_l2_tn_filter_restore(dev);
+	ixgbe_rss_filter_restore(dev);
 
 	return 0;
 }
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h
index 1db29bd..c56d652 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.h
+++ b/drivers/net/ixgbe/ixgbe_ethdev.h
@@ -195,6 +195,12 @@ struct ixgbe_hw_fdir_info {
 	bool mask_added; /* If already got mask from consistent filter */
 };
 
+struct ixgbe_rte_flow_rss_conf {
+	struct rte_eth_rss_conf rss_conf; /**< RSS parameters. */
+	uint16_t num; /**< Number of entries in queue[]. */
+	uint16_t queue[IXGBE_MAX_RX_QUEUE_NUM]; /**< Queues indices to use. */
+};
+
 /* structure for interrupt relative data */
 struct ixgbe_interrupt {
 	uint32_t flags;
@@ -311,6 +317,8 @@ struct ixgbe_filter_info {
 	struct ixgbe_5tuple_filter_list fivetuple_list;
 	/* store the SYN filter info */
 	uint32_t syn_info;
+	/* store the rss filter info */
+	struct ixgbe_rte_flow_rss_conf rss_info;
 };
 
 struct ixgbe_l2_tn_key {
@@ -690,6 +698,8 @@ void ixgbe_tm_conf_init(struct rte_eth_dev *dev);
 void ixgbe_tm_conf_uninit(struct rte_eth_dev *dev);
 int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev, uint16_t queue_idx,
 			       uint16_t tx_rate);
+int ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add);
 
 static inline int
 ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info,
diff --git a/drivers/net/ixgbe/ixgbe_flow.c b/drivers/net/ixgbe/ixgbe_flow.c
index f31aebd..7115a71 100644
--- a/drivers/net/ixgbe/ixgbe_flow.c
+++ b/drivers/net/ixgbe/ixgbe_flow.c
@@ -74,6 +74,11 @@ struct ixgbe_eth_l2_tunnel_conf_ele {
 	TAILQ_ENTRY(ixgbe_eth_l2_tunnel_conf_ele) entries;
 	struct rte_eth_l2_tunnel_conf filter_info;
 };
+/* rss filter list structure */
+struct ixgbe_rss_conf_ele {
+	TAILQ_ENTRY(ixgbe_rss_conf_ele) entries;
+	struct ixgbe_rte_flow_rss_conf filter_info;
+};
 /* ixgbe_flow memory list structure */
 struct ixgbe_flow_mem {
 	TAILQ_ENTRY(ixgbe_flow_mem) entries;
@@ -85,6 +90,7 @@ TAILQ_HEAD(ixgbe_ethertype_filter_list, ixgbe_ethertype_filter_ele);
 TAILQ_HEAD(ixgbe_syn_filter_list, ixgbe_eth_syn_filter_ele);
 TAILQ_HEAD(ixgbe_fdir_rule_filter_list, ixgbe_fdir_rule_ele);
 TAILQ_HEAD(ixgbe_l2_tunnel_filter_list, ixgbe_eth_l2_tunnel_conf_ele);
+TAILQ_HEAD(ixgbe_rss_filter_list, ixgbe_rss_conf_ele);
 TAILQ_HEAD(ixgbe_flow_mem_list, ixgbe_flow_mem);
 
 static struct ixgbe_ntuple_filter_list filter_ntuple_list;
@@ -92,6 +98,7 @@ static struct ixgbe_ethertype_filter_list filter_ethertype_list;
 static struct ixgbe_syn_filter_list filter_syn_list;
 static struct ixgbe_fdir_rule_filter_list filter_fdir_list;
 static struct ixgbe_l2_tunnel_filter_list filter_l2_tunnel_list;
+static struct ixgbe_rss_filter_list filter_rss_list;
 static struct ixgbe_flow_mem_list ixgbe_flow_list;
 
 /**
@@ -2726,6 +2733,109 @@ ixgbe_parse_fdir_filter(struct rte_eth_dev *dev,
 	return ret;
 }
 
+static int
+ixgbe_parse_rss_filter(struct rte_eth_dev *dev,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_action actions[],
+			struct ixgbe_rte_flow_rss_conf *rss_conf,
+			struct rte_flow_error *error)
+{
+	const struct rte_flow_action *act;
+	const struct rte_flow_action_rss *rss;
+	uint16_t n;
+
+	/**
+	 * rss only supports forwarding,
+	 * check if the first not void action is RSS.
+	 */
+	act = next_no_void_action(actions, NULL);
+	if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (!rss || !rss->num) {
+		rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION,
+				act,
+			   "no valid queues");
+		return -rte_errno;
+	}
+
+	for (n = 0; n < rss->num; n++) {
+		if (rss->queue[n] >= dev->data->nb_rx_queues) {
+			rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ACTION,
+				   act,
+				   "queue id > max number of queues");
+			return -rte_errno;
+		}
+	}
+	if (rss->rss_conf)
+		rss_conf->rss_conf = *rss->rss_conf;
+	else
+		rss_conf->rss_conf.rss_hf = IXGBE_RSS_OFFLOAD_ALL;
+
+	for (n = 0; n < rss->num; ++n)
+		rss_conf->queue[n] = rss->queue[n];
+	rss_conf->num = rss->num;
+
+	/* check if the next not void item is END */
+	act = next_no_void_action(actions, act);
+	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+		memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+			RTE_FLOW_ERROR_TYPE_ACTION,
+			act, "Not supported action.");
+		return -rte_errno;
+	}
+
+	/* parse attr */
+	/* must be input direction */
+	if (!attr->ingress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
+				   attr, "Only support ingress.");
+		return -rte_errno;
+	}
+
+	/* not supported */
+	if (attr->egress) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
+				   attr, "Not support egress.");
+		return -rte_errno;
+	}
+
+	if (attr->priority > 0xFFFF) {
+		memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
+				   attr, "Error priority.");
+		return -rte_errno;
+	}
+
+	return 0;
+}
+
+/* remove the rss filter */
+static void
+ixgbe_clear_rss_filter(struct rte_eth_dev *dev)
+{
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	if (filter_info->rss_info.num)
+		ixgbe_config_rss_filter(dev, &filter_info->rss_info, FALSE);
+}
+
 void
 ixgbe_filterlist_init(void)
 {
@@ -2734,6 +2844,7 @@ ixgbe_filterlist_init(void)
 	TAILQ_INIT(&filter_syn_list);
 	TAILQ_INIT(&filter_fdir_list);
 	TAILQ_INIT(&filter_l2_tunnel_list);
+	TAILQ_INIT(&filter_rss_list);
 	TAILQ_INIT(&ixgbe_flow_list);
 }
 
@@ -2746,6 +2857,7 @@ ixgbe_filterlist_flush(void)
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	while ((ntuple_filter_ptr = TAILQ_FIRST(&filter_ntuple_list))) {
 		TAILQ_REMOVE(&filter_ntuple_list,
@@ -2782,6 +2894,13 @@ ixgbe_filterlist_flush(void)
 		rte_free(fdir_rule_ptr);
 	}
 
+	while ((rss_filter_ptr = TAILQ_FIRST(&filter_rss_list))) {
+		TAILQ_REMOVE(&filter_rss_list,
+				 rss_filter_ptr,
+				 entries);
+		rte_free(rss_filter_ptr);
+	}
+
 	while ((ixgbe_flow_mem_ptr = TAILQ_FIRST(&ixgbe_flow_list))) {
 		TAILQ_REMOVE(&ixgbe_flow_list,
 				 ixgbe_flow_mem_ptr,
@@ -2812,12 +2931,14 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	struct rte_flow *flow = NULL;
 	struct ixgbe_ntuple_filter_ele *ntuple_filter_ptr;
 	struct ixgbe_ethertype_filter_ele *ethertype_filter_ptr;
 	struct ixgbe_eth_syn_filter_ele *syn_filter_ptr;
 	struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
 	struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	uint8_t first_mask = FALSE;
 
@@ -3018,6 +3139,29 @@ ixgbe_flow_create(struct rte_eth_dev *dev,
 		}
 	}
 
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
+	if (!ret) {
+		ret = ixgbe_config_rss_filter(dev, &rss_conf, TRUE);
+		if (!ret) {
+			rss_filter_ptr = rte_zmalloc("ixgbe_rss_filter",
+				sizeof(struct ixgbe_rss_conf_ele), 0);
+			if (!rss_filter_ptr) {
+				PMD_DRV_LOG(ERR, "failed to allocate memory");
+				goto out;
+			}
+			rte_memcpy(&rss_filter_ptr->filter_info,
+				&rss_conf,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			TAILQ_INSERT_TAIL(&filter_rss_list,
+				rss_filter_ptr, entries);
+			flow->rule = rss_filter_ptr;
+			flow->filter_type = RTE_ETH_FILTER_HASH;
+			return flow;
+		}
+	}
+
 out:
 	TAILQ_REMOVE(&ixgbe_flow_list,
 		ixgbe_flow_mem_ptr, entries);
@@ -3046,6 +3190,7 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	struct rte_eth_syn_filter syn_filter;
 	struct rte_eth_l2_tunnel_conf l2_tn_filter;
 	struct ixgbe_fdir_rule fdir_rule;
+	struct ixgbe_rte_flow_rss_conf rss_conf;
 	int ret;
 
 	memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -3075,6 +3220,12 @@ ixgbe_flow_validate(struct rte_eth_dev *dev,
 	memset(&l2_tn_filter, 0, sizeof(struct rte_eth_l2_tunnel_conf));
 	ret = ixgbe_parse_l2_tn_filter(dev, attr, pattern,
 				actions, &l2_tn_filter, error);
+	if (!ret)
+		return 0;
+
+	memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
+	ret = ixgbe_parse_rss_filter(dev, attr,
+					actions, &rss_conf, error);
 
 	return ret;
 }
@@ -3101,6 +3252,7 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 	struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
 	struct ixgbe_hw_fdir_info *fdir_info =
 		IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
+	struct ixgbe_rss_conf_ele *rss_filter_ptr;
 
 	switch (filter_type) {
 	case RTE_ETH_FILTER_NTUPLE:
@@ -3169,6 +3321,17 @@ ixgbe_flow_destroy(struct rte_eth_dev *dev,
 			rte_free(l2_tn_filter_ptr);
 		}
 		break;
+	case RTE_ETH_FILTER_HASH:
+		rss_filter_ptr = (struct ixgbe_rss_conf_ele *)
+				pmd_flow->rule;
+		ret = ixgbe_config_rss_filter(dev,
+					&rss_filter_ptr->filter_info, FALSE);
+		if (!ret) {
+			TAILQ_REMOVE(&filter_rss_list,
+				rss_filter_ptr, entries);
+			rte_free(rss_filter_ptr);
+		}
+		break;
 	default:
 		PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
 			    filter_type);
@@ -3220,6 +3383,8 @@ ixgbe_flow_flush(struct rte_eth_dev *dev,
 		return ret;
 	}
 
+	ixgbe_clear_rss_filter(dev);
+
 	ixgbe_filterlist_flush();
 
 	return 0;
diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index 9bc8462..4b38247 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -5550,6 +5550,71 @@ ixgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
 	}
 }
 
+int
+ixgbe_config_rss_filter(struct rte_eth_dev *dev,
+		struct ixgbe_rte_flow_rss_conf *conf, bool add)
+{
+	struct ixgbe_hw *hw;
+	uint32_t reta;
+	uint16_t i;
+	uint16_t j;
+	uint16_t sp_reta_size;
+	uint32_t reta_reg;
+	struct rte_eth_rss_conf rss_conf = conf->rss_conf;
+	struct ixgbe_filter_info *filter_info =
+		IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
+
+	PMD_INIT_FUNC_TRACE();
+	hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
+
+	if (!add) {
+		if (memcmp(conf, &filter_info->rss_info,
+			sizeof(struct ixgbe_rte_flow_rss_conf)) == 0) {
+			ixgbe_rss_disable(dev);
+			memset(&filter_info->rss_info, 0,
+				sizeof(struct ixgbe_rte_flow_rss_conf));
+			return 0;
+		}
+		return -EINVAL;
+	}
+
+	if (filter_info->rss_info.num)
+		return -EINVAL;
+	/* Fill in redirection table
+	 * The byte-swap is needed because NIC registers are in
+	 * little-endian order.
+	 */
+	reta = 0;
+	for (i = 0, j = 0; i < sp_reta_size; i++, j++) {
+		reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
+
+		if (j == conf->num)
+			j = 0;
+		reta = (reta << 8) | conf->queue[j];
+		if ((i & 3) == 3)
+			IXGBE_WRITE_REG(hw, reta_reg,
+					rte_bswap32(reta));
+	}
+
+	/* Configure the RSS key and the RSS protocols used to compute
+	 * the RSS hash of input packets.
+	 */
+	if ((rss_conf.rss_hf & IXGBE_RSS_OFFLOAD_ALL) == 0) {
+		ixgbe_rss_disable(dev);
+		return -EINVAL;
+	}
+	if (rss_conf.rss_key == NULL)
+		rss_conf.rss_key = rss_intel_key; /* Default hash key */
+	ixgbe_hw_rss_hash_set(hw, &rss_conf);
+
+	rte_memcpy(&filter_info->rss_info,
+		conf, sizeof(struct ixgbe_rte_flow_rss_conf));
+
+	return 0;
+}
+
 /* Stubs needed for linkage when CONFIG_RTE_IXGBE_INC_VECTOR is set to 'n' */
 int __attribute__((weak))
 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH v6 0/2] move RSS to flow API
  2018-01-09  6:44         ` [PATCH v6 0/2] " Wei Zhao
  2018-01-09  6:44           ` [PATCH v6 1/2] net/e1000: " Wei Zhao
  2018-01-09  6:44           ` [PATCH v6 2/2] net/ixgbe: " Wei Zhao
@ 2018-01-09  7:11           ` Zhang, Helin
  2 siblings, 0 replies; 28+ messages in thread
From: Zhang, Helin @ 2018-01-09  7:11 UTC (permalink / raw)
  To: Zhao1, Wei, dev; +Cc: Dai, Wei



> -----Original Message-----
> From: Zhao1, Wei
> Sent: Tuesday, January 9, 2018 2:44 PM
> To: dev@dpdk.org
> Cc: Zhang, Helin
> Subject: [PATCH v6 0/2] move RSS to flow API
> 
> The patches mainly finish following functions:
> 1) igb move RSS to flow API
> 2) ixgbe move RSS to flow API
> 
> v2:
> -fix bug for RSS flush code.
> -fix patch check warning.
> 
> v3:
> -fix bug for ixgbe rss restore.
> 
> v4:
> -fix build warning and add release notes comment.
> 
> v5:
> -rebase patch set.
> 
> v6:
> -rebase patch set.
> 
> wei zhao (2):
>   net/e1000: move RSS to flow API
>   net/ixgbe: move RSS to flow API
> 
>  doc/guides/rel_notes/release_18_02.rst |   6 ++
>  drivers/net/e1000/e1000_ethdev.h       |  20 ++++
>  drivers/net/e1000/igb_ethdev.c         |  17 ++++
>  drivers/net/e1000/igb_flow.c           | 160
> ++++++++++++++++++++++++++++++++
>  drivers/net/e1000/igb_rxtx.c           |  61 ++++++++++++
>  drivers/net/ixgbe/ixgbe_ethdev.c       |  13 +++
>  drivers/net/ixgbe/ixgbe_ethdev.h       |  10 ++
>  drivers/net/ixgbe/ixgbe_flow.c         | 165
> +++++++++++++++++++++++++++++++++
>  drivers/net/ixgbe/ixgbe_rxtx.c         |  65 +++++++++++++
>  9 files changed, 517 insertions(+)
> 
> --
> 2.9.3
Applied to dpdk-next-net-intel, with minor commit log changes, thanks!

/Helin

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2018-01-09  7:11 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-23  9:03 [PATCH 1/2] net/e1000: move RSS to flow API Wei Zhao
2017-11-23  9:03 ` [PATCH 2/2] net/ixgbe: " Wei Zhao
2017-11-24  3:10 ` [PATCH v2 0/2] " Wei Zhao
2017-11-24  3:10   ` [PATCH v2 1/2] net/e1000: " Wei Zhao
2017-11-24  3:10   ` [PATCH v2 2/2] net/ixgbe: " Wei Zhao
2017-11-24  8:05   ` [PATCH v3 0/2] " Wei Zhao
2017-11-24  8:05     ` [PATCH v3 1/2] net/e1000: " Wei Zhao
2017-12-07  9:19       ` Dai, Wei
2017-12-08  2:28         ` Zhao1, Wei
2017-12-21  3:11           ` Zhang, Helin
2018-01-04  8:48             ` Zhao1, Wei
2017-11-24  8:05     ` [PATCH v3 2/2] net/ixgbe: " Wei Zhao
2017-12-07  9:19       ` Dai, Wei
2017-12-08  2:27         ` Zhao1, Wei
2017-12-21  3:11           ` Zhang, Helin
2018-01-04  8:51             ` Zhao1, Wei
2018-01-04  7:46     ` [PATCH v4 0/2] " Wei Zhao
2018-01-04  7:46       ` [PATCH v4 1/2] net/e1000: " Wei Zhao
2018-01-05  6:05         ` Dai, Wei
2018-01-04  7:46       ` [PATCH v4 2/2] net/ixgbe: " Wei Zhao
2018-01-05  6:01         ` Dai, Wei
2018-01-09  6:20       ` [PATCH v5 0/2] " Wei Zhao
2018-01-09  6:20         ` [PATCH v5 1/2] net/e1000: " Wei Zhao
2018-01-09  6:20         ` [PATCH v5 2/2] net/ixgbe: " Wei Zhao
2018-01-09  6:44         ` [PATCH v6 0/2] " Wei Zhao
2018-01-09  6:44           ` [PATCH v6 1/2] net/e1000: " Wei Zhao
2018-01-09  6:44           ` [PATCH v6 2/2] net/ixgbe: " Wei Zhao
2018-01-09  7:11           ` [PATCH v6 0/2] " Zhang, Helin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.