Skip to content

Commit

Permalink
Increase optoe's write-max to support i2c block write (sonic-net#230)
Browse files Browse the repository at this point in the history
Dynamic write_max support for optoe driver


Signed-off-by: Prince George <[email protected]>
  • Loading branch information
prgeor authored Aug 18, 2021
1 parent 14a4212 commit ff9762e
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
86 changes: 86 additions & 0 deletions patch/driver-support-optoe-write-max.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
From ca9daf437f0910493a6eb8ced900662223ea3cf7 Mon Sep 17 00:00:00 2001
From: Prince George <[email protected]>
Date: Mon, 16 Aug 2021 16:04:15 +0000
Subject: [PATCH] Dynamic write_max support for optoe driver
In current optoe driver, the value of write_max is hardcoded to one byte.
CMIS spec supports firmware upgrade on QSFP-DD transceivers which means
there is significant overhead due to this one byte write limit when a
platform wants to upgrade the firmware over an i2c bus at 100Khz.
The overhead is more pronounced when a platform has shared master and
platform needs to perform firmware upgrade on multiple transceivers.

Added sysfs file 'write_max' for each i2c device (that use optoe driver)
so that the platform can override the default write max which is one byte.

Test result:-
Firmware file of size 1.9MB takes ~ 33 mins with write-max size = 1 Byte
Firmware file of size 1.9MB takes ~ 8 mins with write-max size = 64 Bytes

Signed-off-by: Prince George <[email protected]>
---
drivers/misc/eeprom/optoe.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)

diff --git a/drivers/misc/eeprom/optoe.c b/drivers/misc/eeprom/optoe.c
index 16287fdc5..cacfb1848 100644
--- a/drivers/misc/eeprom/optoe.c
+++ b/drivers/misc/eeprom/optoe.c
@@ -822,6 +822,39 @@ static int optoe_remove(struct i2c_client *client)
return 0;
}

+static ssize_t show_dev_write_max_size(struct device *dev,
+ struct device_attribute *dattr, char *buf)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct optoe_data *optoe = i2c_get_clientdata(client);
+ ssize_t count;
+
+ mutex_lock(&optoe->lock);
+ count = sprintf(buf, "%u\n", optoe->write_max);
+ mutex_unlock(&optoe->lock);
+
+ return count;
+}
+
+static ssize_t set_dev_write_max_size(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct optoe_data *optoe = i2c_get_clientdata(client);
+ int write_max_size;
+
+ if (kstrtouint(buf, 0, &write_max_size) != 0 ||
+ write_max_size < 1 || write_max_size > OPTOE_PAGE_SIZE)
+ return -EINVAL;
+
+ mutex_lock(&optoe->lock);
+ optoe->write_max = write_max_size;
+ mutex_unlock(&optoe->lock);
+
+ return count;
+}
+
static ssize_t show_dev_class(struct device *dev,
struct device_attribute *dattr, char *buf)
{
@@ -928,12 +961,15 @@ static ssize_t set_port_name(struct device *dev,
static DEVICE_ATTR(port_name, 0644, show_port_name, set_port_name);
#endif /* if NOT defined EEPROM_CLASS, the common case */

+static DEVICE_ATTR(write_max, 0644, show_dev_write_max_size,
+ set_dev_write_max_size);
static DEVICE_ATTR(dev_class, 0644, show_dev_class, set_dev_class);

static struct attribute *optoe_attrs[] = {
#ifndef EEPROM_CLASS
&dev_attr_port_name.attr,
#endif
+ &dev_attr_write_max.attr,
&dev_attr_dev_class.attr,
NULL,
};
--
2.17.1

1 change: 1 addition & 0 deletions patch/series
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ driver-support-optoe.patch
driver-support-optoe-EOF_fix.patch
driver-support-optoe-chunk-offset-fix.patch
driver-support-optoe-QSFP_DD.patch
driver-support-optoe-write-max.patch
driver-net-tg3-add-param-short-preamble-and-reset.patch
0001-hwmon-lm75-add-support-for-PCT2075.patch
0004-dt-bindings-hwmon-Add-missing-documentation-for-lm75.patch
Expand Down

0 comments on commit ff9762e

Please sign in to comment.