DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ajit Khaparde <ajit.khaparde@broadcom.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, Rahul Gupta <rahul.gupta@broadcom.com>,
	Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
Subject: [dpdk-dev] [PATCH 05/17] net/bnxt: add support for RSS action
Date: Mon,  2 Sep 2019 19:18:49 -0700	[thread overview]
Message-ID: <20190903021901.25895-6-ajit.khaparde@broadcom.com> (raw)
In-Reply-To: <20190903021901.25895-1-ajit.khaparde@broadcom.com>

Add support for RSS action during flow creation.

group id should not be 0 when RSS action is specified. Driver will
return an error for such a flow.

If a group id is used to create a filter with “n” RSS queues, it cannot
be used to create a filter with a different number of RSS queues till
all the flows using that combination are deleted.

While creating a flow if a group id groups a certain Rx queue ids for
RSS, the same group id shall not create a flow with a different group of
Rx queue ids till all the flows belonging to the group ids are deleted.

While creating a flow if a group id groups a certain Rx queue ids for
RSS, the same queue ids shall not be used with a different group id till
all flows created with that group id are deleted.

Reviewed-by: Rahul Gupta <rahul.gupta@broadcom.com>
Reviewed-by: Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt_flow.c | 243 +++++++++++++++++++++++++++++++----
 drivers/net/bnxt/bnxt_vnic.c |   2 +-
 drivers/net/bnxt/bnxt_vnic.h |   1 +
 3 files changed, 219 insertions(+), 27 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_flow.c b/drivers/net/bnxt/bnxt_flow.c
index 4ba280fff..1328f25bc 100644
--- a/drivers/net/bnxt/bnxt_flow.c
+++ b/drivers/net/bnxt/bnxt_flow.c
@@ -829,6 +829,60 @@ static int bnxt_vnic_prep(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 	return rc;
 }
 
+static int match_vnic_rss_cfg(struct bnxt *bp,
+			      struct bnxt_vnic_info *vnic,
+			      const struct rte_flow_action_rss *rss)
+{
+	unsigned int match = 0, i;
+
+	if (vnic->rx_queue_cnt != rss->queue_num)
+		return -EINVAL;
+
+	for (i = 0; i < rss->queue_num; i++) {
+		if (!bp->rx_queues[rss->queue[i]]->vnic->rx_queue_cnt &&
+		    !bp->rx_queues[rss->queue[i]]->rx_started)
+			return -EINVAL;
+	}
+
+	for (i = 0; i < vnic->rx_queue_cnt; i++) {
+		int j;
+
+		for (j = 0; j < vnic->rx_queue_cnt; j++) {
+			if (bp->grp_info[rss->queue[i]].fw_grp_id ==
+			    vnic->fw_grp_ids[j])
+				match++;
+		}
+	}
+
+	if (match != vnic->rx_queue_cnt) {
+		PMD_DRV_LOG(ERR,
+			    "VNIC queue count %d vs queues matched %d\n",
+			    match, vnic->rx_queue_cnt);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static void
+bnxt_update_filter_flags_en(struct bnxt_filter_info *filter,
+			    struct bnxt_filter_info *filter1)
+{
+	if (!(filter->valid_flags &
+	      ~(BNXT_FLOW_L2_DST_VALID_FLAG |
+		BNXT_FLOW_L2_SRC_VALID_FLAG |
+		BNXT_FLOW_L2_INNER_SRC_VALID_FLAG |
+		BNXT_FLOW_L2_INNER_DST_VALID_FLAG))) {
+		filter->flags = filter1->flags;
+		filter->enables = filter1->enables;
+		filter->filter_type = HWRM_CFA_L2_FILTER;
+		memset(filter->l2_addr_mask, 0xff, RTE_ETHER_ADDR_LEN);
+		filter->pri_hint = filter1->pri_hint;
+		filter->l2_filter_id_hint = filter1->l2_filter_id_hint;
+	}
+	filter->fw_l2_filter_id = filter1->fw_l2_filter_id;
+}
+
 static int
 bnxt_validate_and_parse_flow(struct rte_eth_dev *dev,
 			     const struct rte_flow_item pattern[],
@@ -842,12 +896,14 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev,
 	struct bnxt *bp = dev->data->dev_private;
 	struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
 	const struct rte_flow_action_queue *act_q;
+	const struct rte_flow_action_rss *rss;
 	const struct rte_flow_action_vf *act_vf;
 	struct bnxt_vnic_info *vnic, *vnic0;
 	struct bnxt_filter_info *filter1;
 	struct bnxt_rx_queue *rxq = NULL;
 	int dflt_vnic, vnic_id;
-	uint32_t vf = 0;
+	unsigned int rss_idx;
+	uint32_t vf = 0, i;
 	int rc;
 
 	rc =
@@ -916,10 +972,13 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev,
 		if (!(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS) && rxq)
 			goto use_vnic;
 
+		//if (!rxq ||
+		    //bp->vnic_info[0].fw_grp_ids[act_q->index] !=
+		    //INVALID_HW_RING_ID ||
+		    //!rxq->rx_deferred_start) {
 		if (!rxq ||
 		    bp->vnic_info[0].fw_grp_ids[act_q->index] !=
-		    INVALID_HW_RING_ID ||
-		    !rxq->rx_deferred_start) {
+		    INVALID_HW_RING_ID) {
 			PMD_DRV_LOG(ERR,
 				    "Queue invalid or used with other VNIC\n");
 			rte_flow_error_set(error,
@@ -931,8 +990,8 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev,
 			goto ret;
 		}
 
-use_vnic:
 		rxq->vnic = vnic;
+		rxq->rx_started = 1;
 		vnic->rx_queue_cnt++;
 		vnic->start_grp_id = act_q->index;
 		vnic->end_grp_id = act_q->index;
@@ -948,6 +1007,7 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev,
 			    "vnic[%d] = %p vnic->fw_grp_ids = %p\n",
 			    act_q->index, vnic, vnic->fw_grp_ids);
 
+use_vnic:
 		vnic->ff_pool_idx = vnic_id;
 		PMD_DRV_LOG(DEBUG,
 			    "Setting vnic ff_idx %d\n", vnic->ff_pool_idx);
@@ -958,20 +1018,8 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev,
 			goto ret;
 		}
 
-		if (!(filter->valid_flags &
-		      ~(BNXT_FLOW_L2_DST_VALID_FLAG |
-			BNXT_FLOW_L2_SRC_VALID_FLAG |
-			BNXT_FLOW_L2_INNER_SRC_VALID_FLAG |
-			BNXT_FLOW_L2_INNER_DST_VALID_FLAG))) {
-			PMD_DRV_LOG(DEBUG, "L2 filter created\n");
-			filter->flags = filter1->flags;
-			filter->enables = filter1->enables;
-			filter->filter_type = HWRM_CFA_L2_FILTER;
-			memset(filter->l2_addr_mask, 0xff, RTE_ETHER_ADDR_LEN);
-			filter->pri_hint = filter1->pri_hint;
-			filter->l2_filter_id_hint = filter1->l2_filter_id_hint;
-		}
-		filter->fw_l2_filter_id = filter1->fw_l2_filter_id;
+		PMD_DRV_LOG(DEBUG, "L2 filter created\n");
+		bnxt_update_filter_flags_en(filter, filter1);
 		break;
 	case RTE_FLOW_ACTION_TYPE_DROP:
 		vnic0 = &bp->vnic_info[0];
@@ -1063,15 +1111,158 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev,
 		filter->fw_l2_filter_id = filter1->fw_l2_filter_id;
 		break;
 	case RTE_FLOW_ACTION_TYPE_RSS:
-		rte_flow_error_set(error,
-				   ENOTSUP,
-				   RTE_FLOW_ERROR_TYPE_ACTION,
-				   act,
-				   "This action is not supported right now.");
-		rc = -rte_errno;
-		goto ret;
-		//break;
+		rss = (const struct rte_flow_action_rss *)act->conf;
+
+		vnic_id = attr->group;
+		if (!vnic_id) {
+			PMD_DRV_LOG(ERR, "Group id cannot be 0\n");
+			rte_flow_error_set(error,
+					   EINVAL,
+					   RTE_FLOW_ERROR_TYPE_ATTR,
+					   NULL,
+					   "Group id cannot be 0");
+			rc = -rte_errno;
+			goto ret;
+		}
+
+		vnic = &bp->vnic_info[vnic_id];
+		if (vnic == NULL) {
+			rte_flow_error_set(error,
+					   EINVAL,
+					   RTE_FLOW_ERROR_TYPE_ACTION,
+					   act,
+					   "No matching VNIC for RSS group.");
+			rc = -rte_errno;
+			goto ret;
+		}
+		PMD_DRV_LOG(DEBUG, "VNIC found\n");
+
+		/* Check if requested RSS config matches RSS config of VNIC
+		 * only if it is not a fresh VNIC configuration.
+		 * Otherwise the existing VNIC configuration can be used.
+		 */
+		if (vnic->rx_queue_cnt) {
+			rc = match_vnic_rss_cfg(bp, vnic, rss);
+			if (rc) {
+				PMD_DRV_LOG(ERR,
+					    "VNIC and RSS config mismatch\n");
+				rte_flow_error_set(error,
+						   EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ACTION,
+						   act,
+						   "VNIC and RSS cfg mismatch");
+				rc = -rte_errno;
+				goto ret;
+			}
+			goto vnic_found;
+		}
+
+		for (i = 0; i < rss->queue_num; i++) {
+			PMD_DRV_LOG(DEBUG, "RSS action Queue %d\n",
+				    rss->queue[i]);
+
+			if (!rss->queue[i] ||
+			    rss->queue[i] >= bp->rx_nr_rings ||
+			    !bp->rx_queues[rss->queue[i]]) {
+				rte_flow_error_set(error,
+						   EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ACTION,
+						   act,
+						   "Invalid queue ID for RSS");
+				rc = -rte_errno;
+				goto ret;
+			}
+			rxq = bp->rx_queues[rss->queue[i]];
 
+			//if (bp->vnic_info[0].fw_grp_ids[rss->queue[i]] !=
+			    //INVALID_HW_RING_ID ||
+			    //!rxq->rx_deferred_start) {
+			if (bp->vnic_info[0].fw_grp_ids[rss->queue[i]] !=
+			    INVALID_HW_RING_ID) {
+				PMD_DRV_LOG(ERR,
+					    "queue active with other VNIC\n");
+				rte_flow_error_set(error,
+						   EINVAL,
+						   RTE_FLOW_ERROR_TYPE_ACTION,
+						   act,
+						   "Invalid queue ID for RSS");
+				rc = -rte_errno;
+				goto ret;
+			}
+
+			rxq->vnic = vnic;
+			rxq->rx_started = 1;
+			vnic->rx_queue_cnt++;
+		}
+
+		vnic->start_grp_id = rss->queue[0];
+		vnic->end_grp_id = rss->queue[rss->queue_num - 1];
+		vnic->func_default = 0;	//This is not a default VNIC.
+
+		rc = bnxt_vnic_prep(bp, vnic);
+		if (rc)
+			goto ret;
+
+		PMD_DRV_LOG(DEBUG,
+			    "vnic[%d] = %p vnic->fw_grp_ids = %p\n",
+			    vnic_id, vnic, vnic->fw_grp_ids);
+
+		vnic->ff_pool_idx = vnic_id;
+		PMD_DRV_LOG(DEBUG,
+			    "Setting vnic ff_pool_idx %d\n", vnic->ff_pool_idx);
+
+		/* This can be done only after vnic_grp_alloc is done. */
+		for (i = 0; i < vnic->rx_queue_cnt; i++) {
+			vnic->fw_grp_ids[i] =
+				bp->grp_info[rss->queue[i]].fw_grp_id;
+			/* Make sure vnic0 does not use these rings. */
+			bp->vnic_info[0].fw_grp_ids[rss->queue[i]] =
+				INVALID_HW_RING_ID;
+		}
+
+		for (rss_idx = 0; rss_idx < HW_HASH_INDEX_SIZE; ) {
+			for (i = 0; i < vnic->rx_queue_cnt; i++)
+				vnic->rss_table[rss_idx++] =
+					vnic->fw_grp_ids[i];
+		}
+
+		/* Configure RSS only if the queue count is > 1 */
+		if (vnic->rx_queue_cnt > 1) {
+			vnic->hash_type =
+				bnxt_rte_to_hwrm_hash_types(rss->types);
+
+			if (!rss->key_len) {
+				/* If hash key has not been specified,
+				 * use random hash key.
+				 */
+				prandom_bytes(vnic->rss_hash_key,
+					      HW_HASH_KEY_SIZE);
+			} else {
+				if (rss->key_len > HW_HASH_KEY_SIZE)
+					memcpy(vnic->rss_hash_key,
+					       rss->key,
+					       HW_HASH_KEY_SIZE);
+				else
+					memcpy(vnic->rss_hash_key,
+					       rss->key,
+					       rss->key_len);
+			}
+			bnxt_hwrm_vnic_rss_cfg(bp, vnic);
+		} else {
+			PMD_DRV_LOG(DEBUG, "No RSS config required\n");
+		}
+
+vnic_found:
+		filter->dst_id = vnic->fw_vnic_id;
+		filter1 = bnxt_get_l2_filter(bp, filter, vnic);
+		if (filter1 == NULL) {
+			rc = -ENOSPC;
+			goto ret;
+		}
+
+		PMD_DRV_LOG(DEBUG, "L2 filter created\n");
+		bnxt_update_filter_flags_en(filter, filter1);
+		break;
 	default:
 		rte_flow_error_set(error,
 				   EINVAL,
diff --git a/drivers/net/bnxt/bnxt_vnic.c b/drivers/net/bnxt/bnxt_vnic.c
index 4f3f9b359..2f0ed1026 100644
--- a/drivers/net/bnxt/bnxt_vnic.c
+++ b/drivers/net/bnxt/bnxt_vnic.c
@@ -16,7 +16,7 @@
  * VNIC Functions
  */
 
-static void prandom_bytes(void *dest_ptr, size_t len)
+void prandom_bytes(void *dest_ptr, size_t len)
 {
 	char *dest = (char *)dest_ptr;
 	uint64_t rb;
diff --git a/drivers/net/bnxt/bnxt_vnic.h b/drivers/net/bnxt/bnxt_vnic.h
index ec3a3ff51..de34b21eb 100644
--- a/drivers/net/bnxt/bnxt_vnic.h
+++ b/drivers/net/bnxt/bnxt_vnic.h
@@ -67,5 +67,6 @@ int bnxt_alloc_vnic_attributes(struct bnxt *bp);
 void bnxt_free_vnic_mem(struct bnxt *bp);
 int bnxt_alloc_vnic_mem(struct bnxt *bp);
 int bnxt_vnic_grp_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic);
+void prandom_bytes(void *dest_ptr, size_t len);
 uint16_t bnxt_rte_to_hwrm_hash_types(uint64_t rte_type);
 #endif
-- 
2.20.1 (Apple Git-117)


  parent reply	other threads:[~2019-09-03  2:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-03  2:18 [dpdk-dev] [PATCH 00/17] bnxt patchset to improve rte flow support Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 01/17] net/bnxt: return standard error codes for HWRM command Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 02/17] net/bnxt: refactor code to allow dynamic creation of VNIC Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 03/17] net/bnxt: allow flow creation when RSS is enabled Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 04/17] net/bnxt: add support to create SMAC and inner DMAC filters Ajit Khaparde
2019-09-03  2:18 ` Ajit Khaparde [this message]
2019-09-03  2:18 ` [dpdk-dev] [PATCH 06/17] net/bnxt: parse priority attribute for flow creation Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 07/17] net/bnxt: delete and flush L2 filters cleanly Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 08/17] net/bnxt: cleanup vnic after flow validate Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 09/17] net/bnxt: allow only unicast MAC address filter creation Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 10/17] net/bnxt: properly handle ring cleanup in case of error Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 11/17] net/bnxt: check device is started before flow creation Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 12/17] net/bnxt: check for invalid VNIC ID in vnic tpa cfg Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 13/17] net/bnxt: handle flow flush handling Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 14/17] net/bnxt: validate RSS hash key length Ajit Khaparde
2019-09-03  2:18 ` [dpdk-dev] [PATCH 15/17] net/bnxt: handle cleanup if flow creation fails Ajit Khaparde
2019-09-03  2:19 ` [dpdk-dev] [PATCH 16/17] net/bnxt: synchronize between flow related functions Ajit Khaparde
2019-09-03  2:19 ` [dpdk-dev] [PATCH 17/17] net/bnxt: drop untagged frames when specified Ajit Khaparde
2019-10-01 17:02 ` [dpdk-dev] [PATCH 00/17] bnxt patchset to improve rte flow support Ferruh Yigit
2019-10-01 17:32   ` Ajit Khaparde

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20190903021901.25895-6-ajit.khaparde@broadcom.com \
    --to=ajit.khaparde@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=rahul.gupta@broadcom.com \
    --cc=venkatkumar.duvvuru@broadcom.com \
    /path/to/YOUR_REPLY

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

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