DPDK patches and discussions
 help / color / mirror / Atom feed
From: Wang Xiao W <xiao.w.wang@intel.com>
To: dev@dpdk.org
Cc: Wang Xiao W <xiao.w.wang@intel.com>
Subject: [dpdk-dev] [PATCH 18/28] fm10k: fix iov_msg_mac_vlan_pf VID checks
Date: Thu, 10 Sep 2015 12:38:27 +0800	[thread overview]
Message-ID: <1441859917-26475-19-git-send-email-xiao.w.wang@intel.com> (raw)
In-Reply-To: <1441859917-26475-1-git-send-email-xiao.w.wang@intel.com>

The VF will send a message to request multicast addresses with the
default vid. In the current code, if the PF has statically assigned a
VLAN to a VF, then the VF will not get the multicast addresses. Fix up
all of the various vlan messages to use identical checks (since each
check was different). Also use set as a variable, so that it simplifies
our check for whether vlan matches the pf_vid.

The new logic will allow set of a vlan if it is zero, automatically
converting to the default vid. Otherwise it will allow setting the PF
vid, or any VLAN if PF has not statically assigned a VLAN. This is
consistent behavior, and allows VF to request either 0 or the
default_vid without silently failing. Note that we need the check for
zero since VFs might not get the default VID message in time to actually
request non-zero VLANs.

Create a function, fm10k_iov_select_vid which implements the logic for
selecting a default vid. This helps us remove duplicate code and
streamlines location of this logic so that we don't make similar bugs in
the future.

Signed-off-by: Wang Xiao W <xiao.w.wang@intel.com>
---
 drivers/net/fm10k/base/fm10k_pf.c | 83 ++++++++++++++++++++++++---------------
 1 file changed, 51 insertions(+), 32 deletions(-)

diff --git a/drivers/net/fm10k/base/fm10k_pf.c b/drivers/net/fm10k/base/fm10k_pf.c
index aa04937..5506568 100644
--- a/drivers/net/fm10k/base/fm10k_pf.c
+++ b/drivers/net/fm10k/base/fm10k_pf.c
@@ -1225,6 +1225,24 @@ s32 fm10k_iov_msg_msix_pf(struct fm10k_hw *hw, u32 **results,
 }
 
 /**
+ * fm10k_iov_select_vid - Select correct default vid
+ * @hw: Pointer to hardware structure
+ * @vid: vid to correct
+ *
+ * Will report an error if vid is out of range. For vid = 0, it will return
+ * either the pf_vid or sw_vid depending on which one is set.
+ */
+STATIC s32 fm10k_iov_select_vid(struct fm10k_vf_info *vf_info, u16 vid)
+{
+	if (!vid)
+		return vf_info->pf_vid ? vf_info->pf_vid : vf_info->sw_vid;
+	else if (vf_info->pf_vid && vid != vf_info->pf_vid)
+		return FM10K_ERR_PARAM;
+	else
+		return vid;
+}
+
+/**
  *  fm10k_iov_msg_mac_vlan_pf - Message handler for MAC/VLAN request from VF
  *  @hw: Pointer to hardware structure
  *  @results: Pointer array to message, results[0] is pointer to message
@@ -1241,6 +1259,7 @@ s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
 	int err = FM10K_SUCCESS;
 	u8 mac[ETH_ALEN];
 	u32 *result;
+	bool set;
 	u16 vlan;
 	u32 vid;
 
@@ -1258,19 +1277,21 @@ s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
 		if (err)
 			return err;
 
-		/* if VLAN ID is 0, set the default VLAN ID instead of 0 */
-		if (!vid || (vid == FM10K_VLAN_CLEAR)) {
-			if (vf_info->pf_vid)
-				vid |= vf_info->pf_vid;
-			else
-				vid |= vf_info->sw_vid;
-		} else if (vid != vf_info->pf_vid) {
+		/* verify upper 16 bits are zero */
+		if (vid >> 16)
 			return FM10K_ERR_PARAM;
-		}
+
+		set = !(vid & FM10K_VLAN_CLEAR);
+		vid &= ~FM10K_VLAN_CLEAR;
+
+		err = fm10k_iov_select_vid(vf_info, (u16)vid);
+		if (err < 0)
+			return err;
+		else
+			vid = err;
 
 		/* update VSI info for VF in regards to VLAN table */
-		err = hw->mac.ops.update_vlan(hw, vid, vf_info->vsi,
-					      !(vid & FM10K_VLAN_CLEAR));
+		err = hw->mac.ops.update_vlan(hw, vid, vf_info->vsi, set);
 	}
 
 	if (!err && !!results[FM10K_MAC_VLAN_MSG_MAC]) {
@@ -1286,19 +1307,18 @@ s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
 		    memcmp(mac, vf_info->mac, ETH_ALEN))
 			return FM10K_ERR_PARAM;
 
-		/* if VLAN ID is 0, set the default VLAN ID instead of 0 */
-		if (!vlan || (vlan == FM10K_VLAN_CLEAR)) {
-			if (vf_info->pf_vid)
-				vlan |= vf_info->pf_vid;
-			else
-				vlan |= vf_info->sw_vid;
-		} else if (vf_info->pf_vid) {
-			return FM10K_ERR_PARAM;
-		}
+		set = !(vlan & FM10K_VLAN_CLEAR);
+		vlan &= ~FM10K_VLAN_CLEAR;
+
+		err = fm10k_iov_select_vid(vf_info, vlan);
+		if (err < 0)
+			return err;
+		else
+			vlan = (u16)err;
 
 		/* notify switch of request for new unicast address */
-		err = hw->mac.ops.update_uc_addr(hw, vf_info->glort, mac, vlan,
-						 !(vlan & FM10K_VLAN_CLEAR), 0);
+		err = hw->mac.ops.update_uc_addr(hw, vf_info->glort,
+						 mac, vlan, set, 0);
 	}
 
 	if (!err && !!results[FM10K_MAC_VLAN_MSG_MULTICAST]) {
@@ -1313,19 +1333,18 @@ s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
 		if (!(vf_info->vf_flags & FM10K_VF_FLAG_MULTI_ENABLED))
 			return FM10K_ERR_PARAM;
 
-		/* if VLAN ID is 0, set the default VLAN ID instead of 0 */
-		if (!vlan || (vlan == FM10K_VLAN_CLEAR)) {
-			if (vf_info->pf_vid)
-				vlan |= vf_info->pf_vid;
-			else
-				vlan |= vf_info->sw_vid;
-		} else if (vf_info->pf_vid) {
-			return FM10K_ERR_PARAM;
-		}
+		set = !(vlan & FM10K_VLAN_CLEAR);
+		vlan &= ~FM10K_VLAN_CLEAR;
+
+		err = fm10k_iov_select_vid(vf_info, vlan);
+		if (err < 0)
+			return err;
+		else
+			vlan = (u16)err;
 
 		/* notify switch of request for new multicast address */
-		err = hw->mac.ops.update_mc_addr(hw, vf_info->glort, mac, vlan,
-						 !(vlan & FM10K_VLAN_CLEAR));
+		err = hw->mac.ops.update_mc_addr(hw, vf_info->glort,
+						 mac, vlan, set);
 	}
 
 	return err;
-- 
1.9.3

  parent reply	other threads:[~2015-09-10  4:39 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-10  4:38 [dpdk-dev] [PATCH 00/28] fm10k: update shared code from ND team Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 01/28] fm10k: add PF Tx Timestamp mode handler function Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 02/28] fm10k: add no-op pointer for VF request_tx_timestamp_mode Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 03/28] fm10k: Set PF queues to unlimited bandwidth Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 04/28] fm10k: fix fm10k_mbx_write_copy header comment Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 05/28] fm10k: Add support for ITR scaling based on PCIe link speed Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 06/28] fm10k: reset head instead of calling update_max_size Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 07/28] fm10k: mbx_update_max_size does not drop all Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 08/28] fm10k: ensure VF restores itr_scale on stop_hw Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 09/28] fm10k: ensure itr_scale is set even if we don't know speed Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 10/28] fm10k: correct VF multicast update Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 11/28] fm10k: Re-map all possible VF queues after a VFLR Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 12/28] fm10k: pack TLV overlay structures correctly Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 13/28] fm10k: 1558 DIR_NEGATIVE bit is actually DIR_POSITIVE Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 14/28] fm10k: remove err_no reference Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 15/28] fm10k: fix iov_msg_lport_state_pf re-enable bug Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 16/28] fm10k: add macro definitions about valid ether addr Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 17/28] fm10k: store actual count of DWORDS pulled/pushed from mbmem Wang Xiao W
2015-09-10  4:38 ` Wang Xiao W [this message]
2015-09-10  4:38 ` [dpdk-dev] [PATCH 19/28] fm10k: Fix Solaris build issue Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 20/28] fm10k: fix Tx FIFO clearing for phantom messages Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 21/28] fm10k: create "correct" header for the remote end on connect Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 22/28] fm10k: do not assume VF always has 1 queue Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 23/28] fm10k: Add support for Boulder Rapids and Atwood Channel Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 24/28] fm10k: remove report_timestamp PF<->VF message Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 25/28] fm10k: remove request_tx_timestamp_mode call Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 26/28] fm10k: add 1588 clock owner message support Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 27/28] fm10k: TRIVIAL fix typo in DEBUGFUNC Wang Xiao W
2015-09-10  4:38 ` [dpdk-dev] [PATCH 28/28] fm10k: add support for MASTER_CLK_OFFSET message Wang Xiao W
2015-10-07 11:40 ` [dpdk-dev] [PATCH 00/28] fm10k: update shared code from ND team Thomas Monjalon

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=1441859917-26475-19-git-send-email-xiao.w.wang@intel.com \
    --to=xiao.w.wang@intel.com \
    --cc=dev@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).