DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ouyang Changchun <changchun.ouyang@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 28/36] ixgbe base codes: Calculate checksum
Date: Thu, 12 Feb 2015 20:01:00 +0800	[thread overview]
Message-ID: <1423742468-30404-29-git-send-email-changchun.ouyang@intel.com> (raw)
In-Reply-To: <1423742468-30404-1-git-send-email-changchun.ouyang@intel.com>

Add function to calculate checksum for X550; and add buffer into argument list
to hold the eeprom image.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
 lib/librte_pmd_ixgbe/ixgbe/ixgbe_x550.c | 74 ++++++++++++++++++++++++---------
 lib/librte_pmd_ixgbe/ixgbe/ixgbe_x550.h |  1 +
 2 files changed, 55 insertions(+), 20 deletions(-)

diff --git a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x550.c b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x550.c
index bdf41da..7c1d5b2 100644
--- a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x550.c
+++ b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x550.c
@@ -1689,19 +1689,28 @@ out:
  * Returns error status for any failure
  */
 STATIC s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
-				   u16 size, u16 *csum)
+				   u16 size, u16 *csum, u16 *buffer,
+				   u32 buffer_size)
 {
 	u16 buf[256];
 	s32 status;
 	u16 length, bufsz, i, start;
+	u16 *local_buffer;
 
 	bufsz = sizeof(buf) / sizeof(buf[0]);
 
 	/* Read a chunk at the pointer location */
-	status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, bufsz, buf);
-	if (status) {
-		DEBUGOUT("Failed to read EEPROM image\n");
-		return status;
+	if (!buffer) {
+		status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, bufsz, buf);
+		if (status) {
+			DEBUGOUT("Failed to read EEPROM image\n");
+			return status;
+		}
+		local_buffer = buf;
+	} else {
+		if (buffer_size < ptr)
+			return  IXGBE_ERR_PARAM;
+		local_buffer = &buffer[ptr];
 	}
 
 	if (size) {
@@ -1709,7 +1718,7 @@ STATIC s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
 		length = size;
 	} else {
 		start = 1;
-		length = buf[0];
+		length = local_buffer[0];
 
 		/* Skip pointer section if length is invalid. */
 		if (length == 0xFFFF || length == 0 ||
@@ -1717,8 +1726,11 @@ STATIC s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
 			return IXGBE_SUCCESS;
 	}
 
+	if (buffer && ((u32)start + (u32)length > buffer_size))
+		return IXGBE_ERR_PARAM;
+
 	for (i = start; length; i++, length--) {
-		if (i == bufsz) {
+		if (i == bufsz && !buffer) {
 			ptr += bufsz;
 			i = 0;
 			if (length < bufsz)
@@ -1732,20 +1744,23 @@ STATIC s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
 				return status;
 			}
 		}
-		*csum += buf[i];
+		*csum += local_buffer[i];
 	}
 	return IXGBE_SUCCESS;
 }
 
 /**
- *  ixgbe_calc_eeprom_checksum_X550 - Calculates and returns the checksum
+ *  ixgbe_calc_checksum_X550 - Calculates and returns the checksum
  *  @hw: pointer to hardware structure
+ *  @buffer: pointer to buffer containing calculated checksum
+ *  @buffer_size: size of buffer
  *
  *  Returns a negative error code on error, or the 16-bit checksum
  **/
-s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
+s32 ixgbe_calc_checksum_X550(struct ixgbe_hw *hw, u16 *buffer, u32 buffer_size)
 {
 	u16 eeprom_ptrs[IXGBE_EEPROM_LAST_WORD + 1];
+	u16 *local_buffer;
 	s32 status;
 	u16 checksum = 0;
 	u16 pointer, i, size;
@@ -1754,13 +1769,20 @@ s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
 
 	hw->eeprom.ops.init_params(hw);
 
-	/* Read pointer area */
-	status = ixgbe_read_ee_hostif_buffer_X550(hw, 0,
-						  IXGBE_EEPROM_LAST_WORD + 1,
-						  eeprom_ptrs);
-	if (status) {
-		DEBUGOUT("Failed to read EEPROM image\n");
-		return status;
+	if (!buffer) {
+		/* Read pointer area */
+		status = ixgbe_read_ee_hostif_buffer_X550(hw, 0,
+						     IXGBE_EEPROM_LAST_WORD + 1,
+						     eeprom_ptrs);
+		if (status) {
+			DEBUGOUT("Failed to read EEPROM image\n");
+			return status;
+		}
+		local_buffer = eeprom_ptrs;
+	} else {
+		if (buffer_size < IXGBE_EEPROM_LAST_WORD)
+			return IXGBE_ERR_PARAM;
+		local_buffer = buffer;
 	}
 
 	/*
@@ -1769,7 +1791,7 @@ s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
 	 */
 	for (i = 0; i <= IXGBE_EEPROM_LAST_WORD; i++)
 		if (i != IXGBE_EEPROM_CHECKSUM)
-			checksum += eeprom_ptrs[i];
+			checksum += local_buffer[i];
 
 	/*
 	 * Include all data from pointers 0x3, 0x6-0xE.  This excludes the
@@ -1779,7 +1801,7 @@ s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
 		if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
 			continue;
 
-		pointer = eeprom_ptrs[i];
+		pointer = local_buffer[i];
 
 		/* Skip pointer section if the pointer is invalid. */
 		if (pointer == 0xFFFF || pointer == 0 ||
@@ -1799,7 +1821,8 @@ s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
 			break;
 		}
 
-		status = ixgbe_checksum_ptr_x550(hw, pointer, size, &checksum);
+		status = ixgbe_checksum_ptr_x550(hw, pointer, size, &checksum,
+						buffer, buffer_size);
 		if (status)
 			return status;
 	}
@@ -1810,6 +1833,17 @@ s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
 }
 
 /**
+ *  ixgbe_calc_eeprom_checksum_X550 - Calculates and returns the checksum
+ *  @hw: pointer to hardware structure
+ *
+ *  Returns a negative error code on error, or the 16-bit checksum
+ **/
+s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
+{
+	return ixgbe_calc_checksum_X550(hw, NULL, 0);
+}
+
+/**
  *  ixgbe_validate_eeprom_checksum_X550 - Validate EEPROM checksum
  *  @hw: pointer to hardware structure
  *  @checksum_val: calculated checksum
diff --git a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x550.h b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x550.h
index 8c78cb1..1aff9b3 100644
--- a/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x550.h
+++ b/lib/librte_pmd_ixgbe/ixgbe/ixgbe_x550.h
@@ -44,6 +44,7 @@ s32 ixgbe_get_bus_info_X550em(struct ixgbe_hw *hw);
 s32 ixgbe_init_eeprom_params_X550(struct ixgbe_hw *hw);
 s32 ixgbe_update_eeprom_checksum_X550(struct ixgbe_hw *hw);
 s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw);
+s32 ixgbe_calc_checksum_X550(struct ixgbe_hw *hw, u16 *buffer, u32 buffer_size);
 s32 ixgbe_validate_eeprom_checksum_X550(struct ixgbe_hw *hw, u16 *checksum_val);
 s32 ixgbe_update_flash_X550(struct ixgbe_hw *hw);
 s32 ixgbe_write_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
-- 
1.8.4.2

  parent reply	other threads:[~2015-02-12 12:02 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-12 12:00 [dpdk-dev] [PATCH 00/36] Update IXGBE base codes Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 01/36] ixgbe base codes: Code cleanup and minor changes Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 02/36] ixgbe base codes: Debug output macro Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 03/36] ixgbe base codes: Fix bus type issue Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 04/36] ixgbe base codes: Fix link speed issue Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 05/36] ixgbe base codes: Fix early return Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 06/36] ixgbe base codes: Update the CS address Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 07/36] ixgbe base codes: Extract function for management capability Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 08/36] ixgbe base codes: Set phy power Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 09/36] ixgbe base codes: Use mng present function Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 10/36] ixgbe base codes: Get host interface command status Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 11/36] ixgbe base codes: Refine function for host interface command Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 12/36] ixgbe base codes: Refine struct for physical information Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 13/36] ixgbe base codes: Clear Tx pending Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 14/36] ixgbe base codes: Use IOMEM Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 15/36] ixgbe base codes: Update macros Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 16/36] ixgbe base codes: New phy ID Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 17/36] ixgbe base codes: Get bus info Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 18/36] ixgbe base codes: Restructure host interface command Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 19/36] ixgbe base codes: Fix mac type issue Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 20/36] ixgbe base codes: API for setup internal phy Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 21/36] ixgbe base codes: API for set phy power Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 22/36] ixgbe base codes: API for read i2c combined Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 23/36] ixgbe base codes: API for write " Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 24/36] ixgbe base codes: Support 5G link speed Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 25/36] ixgbe base codes: Refine branch statement Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 26/36] ixgbe base codes: SFP probe Ouyang Changchun
2015-02-12 12:00 ` [dpdk-dev] [PATCH 27/36] ixgbe base codes: Set LAN ID Ouyang Changchun
2015-02-12 12:01 ` Ouyang Changchun [this message]
2015-02-12 12:01 ` [dpdk-dev] [PATCH 29/36] ixgbe base codes: Command for flow director Ouyang Changchun
2015-02-12 12:01 ` [dpdk-dev] [PATCH 30/36] ixgbe base codes: Auto-negotiation Ouyang Changchun
2015-02-12 12:01 ` [dpdk-dev] [PATCH 31/36] ixgbe base codes: Bit-bang mode Ouyang Changchun
2015-02-12 12:01 ` [dpdk-dev] [PATCH 32/36] ixgbe base codes: Setup kx4 phy Ouyang Changchun
2015-02-12 12:01 ` [dpdk-dev] [PATCH 33/36] ixgbe base codes: Read/write iosf sb stat Ouyang Changchun
2015-02-12 12:01 ` [dpdk-dev] [PATCH 34/36] ixgbe base codes: New device id Ouyang Changchun
2015-02-12 12:01 ` [dpdk-dev] [PATCH 36/36] eal: Add 2 device ids for ixgbe Ouyang Changchun
2015-02-27 14:54 ` [dpdk-dev] [PATCH 00/36] Update IXGBE base codes Liu, Jijiang
2015-04-27 14:59   ` 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=1423742468-30404-29-git-send-email-changchun.ouyang@intel.com \
    --to=changchun.ouyang@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).