DPDK patches and discussions
 help / color / mirror / Atom feed
From: Qi Zhang <qi.z.zhang@intel.com>
To: beilei.xing@intel.com
Cc: dev@dpdk.org, jingjing.wu@intel.com,
	Qi Zhang <qi.z.zhang@intel.com>,
	stable@dpdk.org
Subject: [dpdk-dev] [PATCH v3 21/24] net/i40e/base: fix reading LLDP configuration
Date: Tue,  9 Jan 2018 15:30:19 -0500	[thread overview]
Message-ID: <1515529822-10732-22-git-send-email-qi.z.zhang@intel.com> (raw)
In-Reply-To: <1515529822-10732-1-git-send-email-qi.z.zhang@intel.com>

Previous method for reading LLDP config was based on hard-coded offsets.
It happened to work, because of structured architecture of the NVM memory.
In the new approach, known as FLAT, we need to calculate the absolute
address, instead of using relative values. Needed defines for memory
location were added.

Fixes: 8db9e2a1b232 ("i40e: base driver")
CC: stable@dpdk.org

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---
 drivers/net/i40e/base/i40e_dcb.c  | 88 +++++++++++++++++++++++++++++++++++----
 drivers/net/i40e/base/i40e_type.h |  7 +++-
 2 files changed, 86 insertions(+), 9 deletions(-)

diff --git a/drivers/net/i40e/base/i40e_dcb.c b/drivers/net/i40e/base/i40e_dcb.c
index 9b5405db2..7600c9227 100644
--- a/drivers/net/i40e/base/i40e_dcb.c
+++ b/drivers/net/i40e/base/i40e_dcb.c
@@ -1276,6 +1276,67 @@ enum i40e_status_code i40e_dcb_config_to_lldp(u8 *lldpmib, u16 *miblen,
 }
 
 
+/**
+ * _i40e_read_lldp_cfg - generic read of LLDP Configuration data from NVM
+ * @hw: pointer to the HW structure
+ * @lldp_cfg: pointer to hold lldp configuration variables
+ * @module: address of the module pointer
+ * @word_offset: offset of LLDP configuration
+ *
+ * Reads the LLDP configuration data from NVM using passed addresses
+ **/
+static enum i40e_status_code _i40e_read_lldp_cfg(struct i40e_hw *hw,
+					  struct i40e_lldp_variables *lldp_cfg,
+					  u8 module, u32 word_offset)
+{
+	u32 address, offset = (2 * word_offset);
+	enum i40e_status_code ret;
+	u16 mem;
+
+	ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
+	if (ret != I40E_SUCCESS)
+		return ret;
+
+	ret = i40e_aq_read_nvm(hw, 0x0, module * 2, sizeof(mem), &mem, true,
+			       NULL);
+	i40e_release_nvm(hw);
+	if (ret != I40E_SUCCESS)
+		return ret;
+
+	/* Check if this pointer needs to be read in word size or 4K sector
+	 * units.
+	 */
+	if (mem & I40E_PTR_TYPE)
+		address = (0x7FFF & mem) * 4096;
+	else
+		address = (0x7FFF & mem) * 2;
+
+	ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
+	if (ret != I40E_SUCCESS)
+		goto err_lldp_cfg;
+
+	ret = i40e_aq_read_nvm(hw, module, offset, sizeof(mem), &mem, true,
+			       NULL);
+	i40e_release_nvm(hw);
+	if (ret != I40E_SUCCESS)
+		return ret;
+
+	offset = mem + word_offset;
+	offset *= 2;
+
+	ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
+	if (ret != I40E_SUCCESS)
+		goto err_lldp_cfg;
+
+	ret = i40e_aq_read_nvm(hw, 0, address + offset,
+			       sizeof(struct i40e_lldp_variables), lldp_cfg,
+			       true, NULL);
+	i40e_release_nvm(hw);
+
+err_lldp_cfg:
+	return ret;
+}
+
 /**
  * i40e_read_lldp_cfg - read LLDP Configuration data from NVM
  * @hw: pointer to the HW structure
@@ -1287,21 +1348,34 @@ enum i40e_status_code i40e_read_lldp_cfg(struct i40e_hw *hw,
 					 struct i40e_lldp_variables *lldp_cfg)
 {
 	enum i40e_status_code ret = I40E_SUCCESS;
-	u32 offset = (2 * I40E_NVM_LLDP_CFG_PTR);
+	u32 mem;
 
 	if (!lldp_cfg)
 		return I40E_ERR_PARAM;
 
 	ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
 	if (ret != I40E_SUCCESS)
-		goto err_lldp_cfg;
+		return ret;
 
-	ret = i40e_aq_read_nvm(hw, I40E_SR_EMP_MODULE_PTR, offset,
-			       sizeof(struct i40e_lldp_variables),
-			       (u8 *)lldp_cfg,
-			       true, NULL);
+	ret = i40e_aq_read_nvm(hw, I40E_SR_NVM_CONTROL_WORD, 0, sizeof(mem),
+			       &mem, true, NULL);
 	i40e_release_nvm(hw);
+	if (ret != I40E_SUCCESS)
+		return ret;
+
+	/* Read a bit that holds information whether we are running flat or
+	 * structured NVM image. Flat image has LLDP configuration in shadow
+	 * ram, so there is a need to pass different addresses for both cases.
+	 */
+	if (mem & I40E_SR_NVM_MAP_STRUCTURE_TYPE) {
+		/* Flat NVM case */
+		ret = _i40e_read_lldp_cfg(hw, lldp_cfg, I40E_SR_EMP_MODULE_PTR,
+					  I40E_SR_LLDP_CFG_PTR);
+	} else {
+		/* Good old structured NVM image */
+		ret = _i40e_read_lldp_cfg(hw, lldp_cfg, I40E_EMP_MODULE_PTR,
+					  I40E_NVM_LLDP_CFG_PTR);
+	}
 
-err_lldp_cfg:
 	return ret;
 }
diff --git a/drivers/net/i40e/base/i40e_type.h b/drivers/net/i40e/base/i40e_type.h
index a062816c6..006a11a8a 100644
--- a/drivers/net/i40e/base/i40e_type.h
+++ b/drivers/net/i40e/base/i40e_type.h
@@ -1497,7 +1497,8 @@ struct i40e_hw_port_stats {
 #define I40E_SR_PE_IMAGE_PTR			0x0C
 #define I40E_SR_CSR_PROTECTED_LIST_PTR		0x0D
 #define I40E_SR_MNG_CONFIG_PTR			0x0E
-#define I40E_SR_EMP_MODULE_PTR			0x0F
+#define I40E_EMP_MODULE_PTR			0x0F
+#define I40E_SR_EMP_MODULE_PTR			0x48
 #define I40E_SR_PBA_FLAGS			0x15
 #define I40E_SR_PBA_BLOCK_PTR			0x16
 #define I40E_SR_BOOT_CONFIG_PTR			0x17
@@ -1540,6 +1541,7 @@ struct i40e_hw_port_stats {
 #define I40E_SR_CONTROL_WORD_1_MASK	(0x03 << I40E_SR_CONTROL_WORD_1_SHIFT)
 #define I40E_SR_CONTROL_WORD_1_NVM_BANK_VALID	BIT(5)
 #define I40E_SR_NVM_MAP_STRUCTURE_TYPE		BIT(12)
+#define I40E_PTR_TYPE                           BIT(15)
 
 /* Shadow RAM related */
 #define I40E_SR_SECTOR_SIZE_IN_WORDS	0x800
@@ -1857,7 +1859,8 @@ enum i40e_reset_type {
 };
 
 /* IEEE 802.1AB LLDP Agent Variables from NVM */
-#define I40E_NVM_LLDP_CFG_PTR		0xD
+#define I40E_NVM_LLDP_CFG_PTR   0x06
+#define I40E_SR_LLDP_CFG_PTR    0x31
 struct i40e_lldp_variables {
 	u16 length;
 	u16 adminstatus;
-- 
2.14.1

  parent reply	other threads:[~2018-01-10  3:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-09 20:29 [dpdk-dev] [PATCH v3 00/24] net/i40e: update base code Qi Zhang
2018-01-09 20:29 ` [dpdk-dev] [PATCH v3 01/24] net/i40e/base: add new PHY type Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 02/24] net/i40e/base: add capability macros Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 03/24] net/i40e/base: add (Q)SFP module memory access definitions Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 04/24] net/i40e/base: release spinlock before function returns Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 05/24] net/i40e/base: retry AQC to overcome IRCRead hangs Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 06/24] net/i40e/base: add byte swaps in PHY register access Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 07/24] net/i40e/base: add macro for 25G device Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 08/24] net/i40e/base: code refactoring for LED blink Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 09/24] net/i40e/base: add link speed convert function Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 10/24] net/i40e/base: add AQ command for DCB parameters Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 11/24] net/i40e/base: fix NVM lock Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 12/24] net/i40e/base: code clean Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 13/24] net/i40e/base: add NVM update preservation flags Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 14/24] net/i40e/base: enable AQ event get in NVM update Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 15/24] net/i40e/base: fix link LED blink Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 16/24] net/i40e/base: add defines for flat NVM Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 17/24] net/i40e: enhanced loopback AQ command Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 18/24] net/i40e/base: add rearrange process " Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 19/24] net/i40e/base: add AQ critical error type Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 20/24] net/i40e/base: fix compile issue for GCC 6.3 Qi Zhang
2018-01-09 20:30 ` Qi Zhang [this message]
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 22/24] net/i40e/base: fix unaligned data issue Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 23/24] net/i40e: rename a field Qi Zhang
2018-01-09 20:30 ` [dpdk-dev] [PATCH v3 24/24] net/i40e/base: update README file Qi Zhang
2018-01-10  5:37 ` [dpdk-dev] [PATCH v3 00/24] net/i40e: update base code Xing, Beilei
2018-01-10  9:29   ` Zhang, Helin

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=1515529822-10732-22-git-send-email-qi.z.zhang@intel.com \
    --to=qi.z.zhang@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.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).