diff mbox series

[04/11] net/atlantic: eeprom get/set should consider offset

Message ID 8daab002f486a50a0ad1aa02cd39513c732c94b8.1556525874.git.igor.russkikh@aquantia.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers show
Series Aquantia atlantic bugfixes | expand

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Igor Russkikh April 29, 2019, 8:20 a.m. UTC
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 mbox series

Patch

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;
 }