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,
	Santoshkumar Karanappa Rastapur <santosh.rastapur@broadcom.com>,
	stable@dpdk.org
Subject: [dpdk-dev] [PATCH 20/22] net/bnxt: fix MAC/VLAN filter allocation failure
Date: Thu, 18 Jul 2019 09:06:14 +0530	[thread overview]
Message-ID: <20190718033616.37605-21-ajit.khaparde@broadcom.com> (raw)
In-Reply-To: <20190718033616.37605-1-ajit.khaparde@broadcom.com>

From: Santoshkumar Karanappa Rastapur <santosh.rastapur@broadcom.com>

We were adding the VLAN filters to all the VNICs of the function.
Also, we were adding these VLANs to all the existing MAC only filters.
This was resulting in fewer VLANs getting added. By default we should
allocate MAC+VLAN filter only to the default VNIC of the function using
the default mac address.
Similar logic was followed in the VLAN deletion code. This patch fixes it.
Use inner VLAN fields instead of outer VLAN during filter deletion to be
in sync with VLAN addition code.

Fixes: 246c5cc5f0 ("net/bnxt: use correct flags during VLAN configuration")
Cc: stable@dpdk.org

Signed-off-by: Santoshkumar Karanappa Rastapur <santosh.rastapur@broadcom.com>
Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt.h        |   1 +
 drivers/net/bnxt/bnxt_ethdev.c | 191 +++++++++++++--------------------
 2 files changed, 75 insertions(+), 117 deletions(-)

diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h
index 8bd8f536c..33edb1fcd 100644
--- a/drivers/net/bnxt/bnxt.h
+++ b/drivers/net/bnxt/bnxt.h
@@ -401,6 +401,7 @@ struct bnxt {
 
 	unsigned int		nr_vnics;
 
+#define BNXT_GET_DEFAULT_VNIC(bp)	(&(bp)->vnic_info[0])
 	struct bnxt_vnic_info	*vnic_info;
 	STAILQ_HEAD(, bnxt_vnic_info)	free_vnic_list;
 
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index dd127cd6f..87f069caa 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -1508,141 +1508,98 @@ bnxt_udp_tunnel_port_del_op(struct rte_eth_dev *eth_dev,
 
 static int bnxt_del_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
 {
-	struct bnxt_filter_info *filter, *temp_filter, *new_filter;
+	struct bnxt_filter_info *filter;
 	struct bnxt_vnic_info *vnic;
-	unsigned int i;
 	int rc = 0;
-	uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN;
-
-	/* Cycle through all VNICs */
-	for (i = 0; i < bp->nr_vnics; i++) {
-		/*
-		 * For each VNIC and each associated filter(s)
-		 * if VLAN exists && VLAN matches vlan_id
-		 *      remove the MAC+VLAN filter
-		 *      add a new MAC only filter
-		 * else
-		 *      VLAN filter doesn't exist, just skip and continue
-		 */
-		vnic = &bp->vnic_info[i];
-		filter = STAILQ_FIRST(&vnic->filter);
-		while (filter) {
-			temp_filter = STAILQ_NEXT(filter, next);
+	uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
 
-			if (filter->enables & chk &&
-			    filter->l2_ovlan == vlan_id) {
-				/* Must delete the filter */
-				STAILQ_REMOVE(&vnic->filter, filter,
-					      bnxt_filter_info, next);
-				bnxt_hwrm_clear_l2_filter(bp, filter);
-				STAILQ_INSERT_TAIL(&bp->free_filter_list,
-						   filter, next);
+	/* if VLAN exists && VLAN matches vlan_id
+	 *      remove the MAC+VLAN filter
+	 *      add a new MAC only filter
+	 * else
+	 *      VLAN filter doesn't exist, just skip and continue
+	 */
+	vnic = BNXT_GET_DEFAULT_VNIC(bp);
+	filter = STAILQ_FIRST(&vnic->filter);
+	while (filter) {
+		/* Search for this matching MAC+VLAN filter */
+		if (filter->enables & chk && filter->l2_ivlan == vlan_id &&
+		    !memcmp(filter->l2_addr,
+			    bp->mac_addr,
+			    RTE_ETHER_ADDR_LEN)) {
+			/* Delete the filter */
+			rc = bnxt_hwrm_clear_l2_filter(bp, filter);
+			if (rc)
+				return rc;
+			STAILQ_REMOVE(&vnic->filter, filter,
+				      bnxt_filter_info, next);
+			STAILQ_INSERT_TAIL(&bp->free_filter_list, filter, next);
 
-				/*
-				 * Need to examine to see if the MAC
-				 * filter already existed or not before
-				 * allocating a new one
-				 */
-
-				new_filter = bnxt_alloc_filter(bp);
-				if (!new_filter) {
-					PMD_DRV_LOG(ERR,
-							"MAC/VLAN filter alloc failed\n");
-					rc = -ENOMEM;
-					goto exit;
-				}
-				STAILQ_INSERT_TAIL(&vnic->filter,
-						new_filter, next);
-				/* Inherit MAC from previous filter */
-				new_filter->mac_index =
-					filter->mac_index;
-				memcpy(new_filter->l2_addr, filter->l2_addr,
-				       RTE_ETHER_ADDR_LEN);
-				/* MAC only filter */
-				rc = bnxt_hwrm_set_l2_filter(bp,
-							     vnic->fw_vnic_id,
-							     new_filter);
-				if (rc)
-					goto exit;
-				PMD_DRV_LOG(INFO,
-					    "Del Vlan filter for %d\n",
-					    vlan_id);
-			}
-			filter = temp_filter;
+			PMD_DRV_LOG(INFO,
+				    "Del Vlan filter for %d\n",
+				    vlan_id);
+			return rc;
 		}
+		filter = STAILQ_NEXT(filter, next);
 	}
-exit:
-	return rc;
+	return -ENOENT;
 }
 
 static int bnxt_add_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
 {
-	struct bnxt_filter_info *filter, *temp_filter, *new_filter;
+	struct bnxt_filter_info *filter;
 	struct bnxt_vnic_info *vnic;
-	unsigned int i;
 	int rc = 0;
 	uint32_t en = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
 		HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
 	uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
 
-	/* Cycle through all VNICs */
-	for (i = 0; i < bp->nr_vnics; i++) {
-		/*
-		 * For each VNIC and each associated filter(s)
-		 * if VLAN exists:
-		 *   if VLAN matches vlan_id
-		 *      VLAN filter already exists, just skip and continue
-		 *   else
-		 *      add a new MAC+VLAN filter
-		 * else
-		 *   Remove the old MAC only filter
-		 *    Add a new MAC+VLAN filter
-		 */
-		vnic = &bp->vnic_info[i];
-		filter = STAILQ_FIRST(&vnic->filter);
-		while (filter) {
-			temp_filter = STAILQ_NEXT(filter, next);
+	/* Implementation notes on the use of VNIC in this command:
+	 *
+	 * By default, these filters belong to default vnic for the function.
+	 * Once these filters are set up, only destination VNIC can be modified.
+	 * If the destination VNIC is not specified in this command,
+	 * then the HWRM shall only create an l2 context id.
+	 */
 
-			if (filter->enables & chk) {
-				if (filter->l2_ivlan == vlan_id)
-					goto cont;
-			} else {
-				/* Must delete the MAC filter */
-				STAILQ_REMOVE(&vnic->filter, filter,
-						bnxt_filter_info, next);
-				bnxt_hwrm_clear_l2_filter(bp, filter);
-				filter->l2_ovlan = 0;
-				STAILQ_INSERT_TAIL(&bp->free_filter_list,
-						   filter, next);
-			}
-			new_filter = bnxt_alloc_filter(bp);
-			if (!new_filter) {
-				PMD_DRV_LOG(ERR,
-						"MAC/VLAN filter alloc failed\n");
-				rc = -ENOMEM;
-				goto exit;
-			}
-			STAILQ_INSERT_TAIL(&vnic->filter, new_filter, next);
-			/* Inherit MAC from the previous filter */
-			new_filter->mac_index = filter->mac_index;
-			memcpy(new_filter->l2_addr, filter->l2_addr,
-			       RTE_ETHER_ADDR_LEN);
-			/* MAC + VLAN ID filter */
-			new_filter->l2_ivlan = vlan_id;
-			new_filter->l2_ivlan_mask = 0xF000;
-			new_filter->enables |= en;
-			rc = bnxt_hwrm_set_l2_filter(bp,
-					vnic->fw_vnic_id,
-					new_filter);
-			if (rc)
-				goto exit;
-			PMD_DRV_LOG(INFO,
-				    "Added Vlan filter for %d\n", vlan_id);
-cont:
-			filter = temp_filter;
-		}
+	vnic = BNXT_GET_DEFAULT_VNIC(bp);
+	filter = STAILQ_FIRST(&vnic->filter);
+	/* Check if the VLAN has already been added */
+	while (filter) {
+		if (filter->enables & chk && filter->l2_ivlan == vlan_id &&
+		    !memcmp(filter->l2_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN))
+			return -EEXIST;
+
+		filter = STAILQ_NEXT(filter, next);
 	}
-exit:
+
+	/* No match found. Alloc a fresh filter and issue the L2_FILTER_ALLOC
+	 * command to create MAC+VLAN filter with the right flags, enables set.
+	 */
+	filter = bnxt_alloc_filter(bp);
+	if (!filter) {
+		PMD_DRV_LOG(ERR,
+			    "MAC/VLAN filter alloc failed\n");
+		return -ENOMEM;
+	}
+	/* MAC + VLAN ID filter */
+	filter->l2_ivlan = vlan_id;
+	filter->l2_ivlan_mask = 0x0FFF;
+	filter->enables |= en;
+	rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
+	if (rc) {
+		/* Free the newly allocated filter as we were
+		 * not able to create the filter in hardware.
+		 */
+		filter->fw_l2_filter_id = UINT64_MAX;
+		STAILQ_INSERT_TAIL(&bp->free_filter_list, filter, next);
+		return rc;
+	}
+
+	/* Add this new filter to the list */
+	STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
+	PMD_DRV_LOG(INFO,
+		    "Added Vlan filter for %d\n", vlan_id);
 	return rc;
 }
 
-- 
2.20.1 (Apple Git-117)


  parent reply	other threads:[~2019-07-18  3:39 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-18  3:35 [dpdk-dev] [PATCH 00/22] bnxt patchset Ajit Khaparde
2019-07-18  3:35 ` [dpdk-dev] [PATCH 01/22] net/bnxt: fix to handle error case during port start Ajit Khaparde
2019-07-18  3:35 ` [dpdk-dev] [PATCH 02/22] net/bnxt: fix return value check of address mapping Ajit Khaparde
2019-07-18  3:35 ` [dpdk-dev] [PATCH 03/22] net/bnxt: fix failure to add a MAC address Ajit Khaparde
2019-07-18  3:35 ` [dpdk-dev] [PATCH 04/22] net/bnxt: fix an unconditional wait in link update Ajit Khaparde
2019-07-18  3:35 ` [dpdk-dev] [PATCH 05/22] net/bnxt: fix setting primary MAC address Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 06/22] net/bnxt: fix failure path in dev init Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 07/22] net/bnxt: reset filters before registering interrupts Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 08/22] net/bnxt: use correct vnic default completion ring Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 09/22] net/bnxt: use dedicated cpr for async events Ajit Khaparde
2019-07-22 14:57   ` Ferruh Yigit
2019-07-22 15:06     ` Thomas Monjalon
2019-07-22 17:57       ` Lance Richardson
2019-07-22 18:34         ` Ferruh Yigit
2019-07-23  8:04           ` Thomas Monjalon
2019-07-23 10:53             ` Lance Richardson
2019-07-23 21:27           ` Lance Richardson
2019-07-24 16:14   ` [dpdk-dev] [PATCH] " Lance Richardson
2019-07-24 16:32     ` Lance Richardson
2019-07-24 16:49     ` [dpdk-dev] [[PATCH v2]] " Lance Richardson
2019-07-25  9:54       ` Ferruh Yigit
2019-07-18  3:36 ` [dpdk-dev] [PATCH 10/22] net/bnxt: retry irq callback deregistration Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 11/22] net/bnxt: fix error checking of FW commands Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 12/22] net/bnxt: fix to return standard error codes Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 13/22] net/bnxt: fix lock release on getting NVM info Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 14/22] net/bnxt: fix RSS disable issue for thor-based adapters Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 15/22] net/bnxt: use correct RSS table sizes Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 16/22] net/bnxt: fully initialize hwrm msgs for thor RSS cfg Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 17/22] net/bnxt: use correct number of RSS contexts for thor Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 18/22] net/bnxt: pass correct RSS table address " Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 19/22] net/bnxt: avoid overrun in get statistics Ajit Khaparde
2019-07-18  3:36 ` Ajit Khaparde [this message]
2019-07-18  3:36 ` [dpdk-dev] [PATCH 21/22] net/bnxt: fix to correctly check result of HWRM command Ajit Khaparde
2019-07-18  3:36 ` [dpdk-dev] [PATCH 22/22] net/bnxt: update HWRM API to version 1.10.0.91 Ajit Khaparde
2019-07-19 12:30 ` [dpdk-dev] [PATCH 00/22] bnxt patchset Ferruh Yigit
2019-07-19 13:22   ` Ajit Kumar Khaparde
2019-07-19 16:59     ` Ferruh Yigit
2019-07-19 21:01 ` Ferruh Yigit

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20190718033616.37605-21-ajit.khaparde@broadcom.com \
    --to=ajit.khaparde@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=santosh.rastapur@broadcom.com \
    --cc=stable@dpdk.org \
    /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).