DPDK patches and discussions
 help / color / mirror / Atom feed
From: Igor Russkikh <Igor.Russkikh@aquantia.com>
To: "dev@dpdk.org" <dev@dpdk.org>
Cc: Pavel Belous <Pavel.Belous@aquantia.com>,
	Igor Russkikh <Igor.Russkikh@aquantia.com>,
	"stable@dpdk.org" <stable@dpdk.org>
Subject: [dpdk-dev] [PATCH 04/11] net/atlantic: eeprom get/set should consider offset
Date: Mon, 29 Apr 2019 08:20:15 +0000	[thread overview]
Message-ID: <8daab002f486a50a0ad1aa02cd39513c732c94b8.1556525874.git.igor.russkikh@aquantia.com> (raw)
Message-ID: <20190429082015.iRxDf_qSaQCcMbEC4nLc0K-LC8KEpmIwfsE6J1QYK2I@z> (raw)
In-Reply-To: <cover.1556525874.git.igor.russkikh@aquantia.com>

From: Pavel Belous <pavel.belous@aquantia.com>

EEPROM get/set offset logic should take offset into account.
Data transfers to/from FW should also correctly use
dword based transfer interface, taking into account the
remainder.
We also check error code returned from FW.

cc: stable@dpdk.org
Fixes: ce4e8d418097 ("net/atlantic: implement EEPROM get/set")
Signed-off-by: Igor Russkikh <igor.russkikh@aquantia.com>
Signed-off-by: Pavel Belous <pavel.belous@aquantia.com>
---
 drivers/net/atlantic/atl_ethdev.c             |  7 +-
 drivers/net/atlantic/atl_types.h              |  2 +-
 drivers/net/atlantic/hw_atl/hw_atl_utils.h    | 11 +--
 .../net/atlantic/hw_atl/hw_atl_utils_fw2x.c   | 95 ++++++++++++-------
 4 files changed, 68 insertions(+), 47 deletions(-)

diff --git a/drivers/net/atlantic/atl_ethdev.c b/drivers/net/atlantic/atl_ethdev.c
index 4e6124aa318e..7be97ab3095e 100644
--- a/drivers/net/atlantic/atl_ethdev.c
+++ b/drivers/net/atlantic/atl_ethdev.c
@@ -1448,14 +1448,15 @@ int atl_dev_set_eeprom(struct rte_eth_dev *dev,
 	if (hw->aq_fw_ops->set_eeprom == NULL)
 		return -ENOTSUP;
 
-	if (eeprom->length != SFP_EEPROM_SIZE || eeprom->data == NULL)
+	if (eeprom->length + eeprom->offset > SFP_EEPROM_SIZE ||
+	    eeprom->data == NULL)
 		return -EINVAL;
 
 	if (eeprom->magic)
 		dev_addr = eeprom->magic;
 
-	return hw->aq_fw_ops->set_eeprom(hw, dev_addr,
-					 eeprom->data, eeprom->length);
+	return hw->aq_fw_ops->set_eeprom(hw, dev_addr, eeprom->data,
+					 eeprom->length, eeprom->offset);
 }
 
 static int
diff --git a/drivers/net/atlantic/atl_types.h b/drivers/net/atlantic/atl_types.h
index dbaf2c635f50..84a4776951db 100644
--- a/drivers/net/atlantic/atl_types.h
+++ b/drivers/net/atlantic/atl_types.h
@@ -177,7 +177,7 @@ struct aq_fw_ops {
 			  u32 *data, u32 len, u32 offset);
 
 	int (*set_eeprom)(struct aq_hw_s *self, int dev_addr,
-			  u32 *data, u32 len);
+			  u32 *data, u32 len, u32 offset);
 
 	int (*send_macsec_req)(struct aq_hw_s *self,
 			       struct macsec_msg_fw_request *req,
diff --git a/drivers/net/atlantic/hw_atl/hw_atl_utils.h b/drivers/net/atlantic/hw_atl/hw_atl_utils.h
index b7c531573623..81caffaedfd0 100644
--- a/drivers/net/atlantic/hw_atl/hw_atl_utils.h
+++ b/drivers/net/atlantic/hw_atl/hw_atl_utils.h
@@ -337,15 +337,8 @@ struct offload_info {
 	u8 buf[0];
 } __attribute__((__packed__));
 
-struct smbus_read_request {
-	u32 offset; /* not used */
-	u32 device_id;
-	u32 address;
-	u32 length;
-} __attribute__((__packed__));
-
-struct smbus_write_request {
-	u32 offset; /* not used */
+struct smbus_request {
+	u32 msg_id; /* not used */
 	u32 device_id;
 	u32 address;
 	u32 length;
diff --git a/drivers/net/atlantic/hw_atl/hw_atl_utils_fw2x.c b/drivers/net/atlantic/hw_atl/hw_atl_utils_fw2x.c
index 89a3759b89b4..de4189441fad 100644
--- a/drivers/net/atlantic/hw_atl/hw_atl_utils_fw2x.c
+++ b/drivers/net/atlantic/hw_atl/hw_atl_utils_fw2x.c
@@ -498,14 +498,17 @@ static int aq_fw2x_led_control(struct aq_hw_s *self, u32 mode)
 static int aq_fw2x_get_eeprom(struct aq_hw_s *self, int dev_addr,
 			      u32 *data, u32 len, u32 offset)
 {
-	int err = 0;
-	struct smbus_read_request request;
-	u32 mpi_opts;
+	u32 bytes_remains = len % sizeof(u32);
+	u32 num_dwords = len / sizeof(u32);
+	struct smbus_request request;
 	u32 result = 0;
+	u32 mpi_opts;
+	int err = 0;
 
 	if (self->fw_ver_actual < HW_ATL_FW_FEATURE_EEPROM)
 		return -EOPNOTSUPP;
 
+	request.msg_id = 0;
 	request.device_id = dev_addr;
 	request.address = offset;
 	request.length = len;
@@ -540,34 +543,33 @@ static int aq_fw2x_get_eeprom(struct aq_hw_s *self, int dev_addr,
 	if (err < 0)
 		return err;
 
-	if (result == 0) {
-		u32 num_dwords = len / sizeof(u32);
-		u32 bytes_remains = len % sizeof(u32);
+	if (result)
+		return -EIO;
 
-		if (num_dwords) {
-			err = hw_atl_utils_fw_downld_dwords(self,
-				self->rpc_addr + sizeof(u32) * 2,
-				data,
-				num_dwords);
+	if (num_dwords) {
+		err = hw_atl_utils_fw_downld_dwords(self,
+			self->rpc_addr + sizeof(u32) * 2,
+			data,
+			num_dwords);
 
-			if (err < 0)
-				return err;
-		}
+		if (err < 0)
+			return err;
+	}
 
-		if (bytes_remains) {
-			u32 val = 0;
+	if (bytes_remains) {
+		u32 val = 0;
 
-			err = hw_atl_utils_fw_downld_dwords(self,
-				self->rpc_addr + sizeof(u32) * 2 + num_dwords,
-				&val,
-				sizeof(u32));
+		err = hw_atl_utils_fw_downld_dwords(self,
+			self->rpc_addr + (sizeof(u32) * 2) +
+			(num_dwords * sizeof(u32)),
+			&val,
+			1);
 
-			if (err < 0)
-				return err;
+		if (err < 0)
+			return err;
 
-			rte_memcpy((u8 *)data + len - bytes_remains,
-				   &val, bytes_remains);
-		}
+		rte_memcpy((u8 *)data + len - bytes_remains,
+				&val, bytes_remains);
 	}
 
 	return 0;
@@ -575,17 +577,18 @@ static int aq_fw2x_get_eeprom(struct aq_hw_s *self, int dev_addr,
 
 
 static int aq_fw2x_set_eeprom(struct aq_hw_s *self, int dev_addr,
-			      u32 *data, u32 len)
+			      u32 *data, u32 len, u32 offset)
 {
-	struct smbus_write_request request;
+	struct smbus_request request;
 	u32 mpi_opts, result = 0;
 	int err = 0;
 
 	if (self->fw_ver_actual < HW_ATL_FW_FEATURE_EEPROM)
 		return -EOPNOTSUPP;
 
+	request.msg_id = 0;
 	request.device_id = dev_addr;
-	request.address = 0;
+	request.address = offset;
 	request.length = len;
 
 	/* Write SMBUS request to cfg memory */
@@ -597,13 +600,34 @@ static int aq_fw2x_set_eeprom(struct aq_hw_s *self, int dev_addr,
 		return err;
 
 	/* Write SMBUS data to cfg memory */
-	err = hw_atl_utils_fw_upload_dwords(self,
-				self->rpc_addr + sizeof(request),
-				(u32 *)(void *)data,
-				RTE_ALIGN(len, sizeof(u32)));
+	u32 num_dwords = len / sizeof(u32);
+	u32 bytes_remains = len % sizeof(u32);
 
-	if (err < 0)
-		return err;
+	if (num_dwords) {
+		err = hw_atl_utils_fw_upload_dwords(self,
+			self->rpc_addr + sizeof(request),
+			(u32 *)(void *)data,
+			num_dwords);
+
+		if (err < 0)
+			return err;
+	}
+
+	if (bytes_remains) {
+		u32 val = 0;
+
+		rte_memcpy(&val, (u8 *)data + (sizeof(u32) * num_dwords),
+			   bytes_remains);
+
+		err = hw_atl_utils_fw_upload_dwords(self,
+			self->rpc_addr + sizeof(request) +
+			(num_dwords * sizeof(u32)),
+			&val,
+			1);
+
+		if (err < 0)
+			return err;
+	}
 
 	/* Toggle 0x368.CAPS_LO_SMBUS_WRITE bit */
 	mpi_opts = aq_hw_read_reg(self, HW_ATL_FW2X_MPI_CONTROL_ADDR);
@@ -627,6 +651,9 @@ static int aq_fw2x_set_eeprom(struct aq_hw_s *self, int dev_addr,
 	if (err < 0)
 		return err;
 
+	if (result)
+		return -EIO;
+
 	return 0;
 }
 
-- 
2.17.1


  parent reply	other threads:[~2019-04-29  8:20 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-29  8:20 [dpdk-dev] [PATCH 00/11] Aquantia atlantic bugfixes Igor Russkikh
2019-04-29  8:20 ` Igor Russkikh
2019-04-29  8:20 ` [dpdk-dev] [PATCH 01/11] net/atlantic: enable broadcast traffic Igor Russkikh
2019-04-29  8:20   ` Igor Russkikh
2019-04-29  8:20 ` [dpdk-dev] [PATCH 02/11] net/atlantic: extra line at eof Igor Russkikh
2019-04-29  8:20   ` Igor Russkikh
2019-04-29 13:57   ` Ferruh Yigit
2019-04-29 13:57     ` Ferruh Yigit
2019-04-29  8:20 ` [dpdk-dev] [PATCH 03/11] net/atlantic: bad indentation Igor Russkikh
2019-04-29  8:20   ` Igor Russkikh
2019-04-29  8:20 ` Igor Russkikh [this message]
2019-04-29  8:20   ` [dpdk-dev] [PATCH 04/11] net/atlantic: eeprom get/set should consider offset Igor Russkikh
2019-04-29  8:20 ` [dpdk-dev] [PATCH 05/11] net/atlantic: fix max eeprom size Igor Russkikh
2019-04-29  8:20   ` Igor Russkikh
2019-04-29  8:20 ` [dpdk-dev] [PATCH 06/11] net/atlantic: validity check for eeprom dev address Igor Russkikh
2019-04-29  8:20   ` Igor Russkikh
2019-04-29  8:20 ` [dpdk-dev] [PATCH 07/11] net/atlantic: bad logic with offsets talking with firmware Igor Russkikh
2019-04-29  8:20   ` Igor Russkikh
2019-04-29  8:20 ` [dpdk-dev] [PATCH 08/11] net/atlantic: flow control settings synchronization on rx Igor Russkikh
2019-04-29  8:20   ` Igor Russkikh
2019-04-29  8:20 ` [dpdk-dev] [PATCH 09/11] net/atlantic: use capability bits to detect eeprom access Igor Russkikh
2019-04-29  8:20   ` Igor Russkikh
2019-04-29  8:20 ` [dpdk-dev] [PATCH 10/11] net/atlantic: typo on args check Igor Russkikh
2019-04-29  8:20   ` Igor Russkikh
2019-04-29  8:20 ` [dpdk-dev] [PATCH 11/11] net/atlantic: extra err check Igor Russkikh
2019-04-29  8:20   ` Igor Russkikh
2019-05-08 16:05 ` [dpdk-dev] [PATCH 00/11] Aquantia atlantic bugfixes Kevin Traynor
2019-05-08 16:05   ` Kevin Traynor
2019-05-13  7:59   ` Igor Russkikh
2019-05-13  7:59     ` Igor Russkikh

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=8daab002f486a50a0ad1aa02cd39513c732c94b8.1556525874.git.igor.russkikh@aquantia.com \
    --to=igor.russkikh@aquantia.com \
    --cc=Pavel.Belous@aquantia.com \
    --cc=dev@dpdk.org \
    --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).