|
| 1 | +From 4d5ae45bdd2623d65b6d3bac13c66663e24448c5 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Mihir Patel < [email protected]> |
| 3 | +Date: Fri, 15 Dec 2023 22:41:34 +0000 |
| 4 | +Subject: [PATCH] Dynamic write timeout support for optoe driver |
| 5 | + |
| 6 | +The optoe kernel driver currently has a fixed 25ms write timeout value. We need to provide an interface to support overwriting the write_timeout value from userspace. |
| 7 | +The overwriting of the write timeout value is needed for some non-standard optics which are not compliant with the timeout value in spec and will help in resolving issues related to EEPROM access. |
| 8 | +The overwriting of the write_timeout value can be done based on platform or vendor of the transceiver. |
| 9 | +Following sysfs will be created with this change |
| 10 | +/sys/bus/i2c/devices/<bus_id>-0050/write_timeout |
| 11 | + |
| 12 | +Testing |
| 13 | +root@sonic:/sys/bus/i2c/devices/31-0050# ls |
| 14 | +dev_class driver eeprom modalias name port_name power subsystem uevent write_max write_timeout |
| 15 | +root@sonic:/sys/bus/i2c/devices/31-0050# |
| 16 | + |
| 17 | +Signed-off-by: Mihir Patel < [email protected]> |
| 18 | +--- |
| 19 | + ...driver-support-dynamic-write-timeout.patch | 105 ++++++++++++++++++ |
| 20 | + 1 file changed, 105 insertions(+) |
| 21 | + |
| 22 | +diff --git a/drivers/misc/eeprom/optoe.c b/drivers/misc/eeprom/optoe.c |
| 23 | +index 394c19944..a54a9ee1b 100644 |
| 24 | +--- a/drivers/misc/eeprom/optoe.c |
| 25 | ++++ b/drivers/misc/eeprom/optoe.c |
| 26 | +@@ -194,6 +194,7 @@ struct optoe_data { |
| 27 | + |
| 28 | + u8 *writebuf; |
| 29 | + unsigned int write_max; |
| 30 | ++ unsigned int write_timeout; |
| 31 | + |
| 32 | + unsigned int num_addresses; |
| 33 | + |
| 34 | +@@ -223,7 +224,8 @@ static unsigned int io_limit = OPTOE_PAGE_SIZE; |
| 35 | + * specs often allow 5 msec for a page write, sometimes 20 msec; |
| 36 | + * it's important to recover from write timeouts. |
| 37 | + */ |
| 38 | +-static unsigned int write_timeout = 25; |
| 39 | ++#define OPTOE_DEFAULT_WRITE_TIMEOUT 25 |
| 40 | ++#define OPTOE_MAX_SUPPORTED_WRITE_TIMEOUT 500 |
| 41 | + |
| 42 | + /* |
| 43 | + * flags to distinguish one-address (QSFP family) from two-address (SFP family) |
| 44 | +@@ -352,7 +354,7 @@ static ssize_t optoe_eeprom_read(struct optoe_data *optoe, |
| 45 | + * loop a few times until this one succeeds, waiting at least |
| 46 | + * long enough for one entire page write to work. |
| 47 | + */ |
| 48 | +- timeout = jiffies + msecs_to_jiffies(write_timeout); |
| 49 | ++ timeout = jiffies + msecs_to_jiffies(optoe->write_timeout); |
| 50 | + do { |
| 51 | + read_time = jiffies; |
| 52 | + |
| 53 | +@@ -453,7 +455,7 @@ static ssize_t optoe_eeprom_write(struct optoe_data *optoe, |
| 54 | + * loop a few times until this one succeeds, waiting at least |
| 55 | + * long enough for one entire page write to work. |
| 56 | + */ |
| 57 | +- timeout = jiffies + msecs_to_jiffies(write_timeout); |
| 58 | ++ timeout = jiffies + msecs_to_jiffies(optoe->write_timeout); |
| 59 | + do { |
| 60 | + write_time = jiffies; |
| 61 | + |
| 62 | +@@ -855,6 +857,39 @@ static ssize_t set_dev_write_max_size(struct device *dev, |
| 63 | + return count; |
| 64 | + } |
| 65 | + |
| 66 | ++static ssize_t show_dev_write_timeout_size(struct device *dev, |
| 67 | ++ struct device_attribute *dattr, char *buf) |
| 68 | ++{ |
| 69 | ++ struct i2c_client *client = to_i2c_client(dev); |
| 70 | ++ struct optoe_data *optoe = i2c_get_clientdata(client); |
| 71 | ++ ssize_t count; |
| 72 | ++ |
| 73 | ++ mutex_lock(&optoe->lock); |
| 74 | ++ count = sprintf(buf, "%u\n", optoe->write_timeout); |
| 75 | ++ mutex_unlock(&optoe->lock); |
| 76 | ++ |
| 77 | ++ return count; |
| 78 | ++} |
| 79 | ++ |
| 80 | ++static ssize_t set_dev_write_timeout_size(struct device *dev, |
| 81 | ++ struct device_attribute *attr, |
| 82 | ++ const char *buf, size_t count) |
| 83 | ++{ |
| 84 | ++ struct i2c_client *client = to_i2c_client(dev); |
| 85 | ++ struct optoe_data *optoe = i2c_get_clientdata(client); |
| 86 | ++ unsigned int write_timeout_size; |
| 87 | ++ |
| 88 | ++ if (kstrtouint(buf, 0, &write_timeout_size) != 0 || |
| 89 | ++ write_timeout_size < 0 || write_timeout_size > OPTOE_MAX_SUPPORTED_WRITE_TIMEOUT) |
| 90 | ++ return -EINVAL; |
| 91 | ++ |
| 92 | ++ mutex_lock(&optoe->lock); |
| 93 | ++ optoe->write_timeout = write_timeout_size; |
| 94 | ++ mutex_unlock(&optoe->lock); |
| 95 | ++ |
| 96 | ++ return count; |
| 97 | ++} |
| 98 | ++ |
| 99 | + static ssize_t show_dev_class(struct device *dev, |
| 100 | + struct device_attribute *dattr, char *buf) |
| 101 | + { |
| 102 | +@@ -961,6 +996,8 @@ static ssize_t set_port_name(struct device *dev, |
| 103 | + static DEVICE_ATTR(port_name, 0644, show_port_name, set_port_name); |
| 104 | + #endif /* if NOT defined EEPROM_CLASS, the common case */ |
| 105 | + |
| 106 | ++static DEVICE_ATTR(write_timeout, 0644, show_dev_write_timeout_size, |
| 107 | ++ set_dev_write_timeout_size); |
| 108 | + static DEVICE_ATTR(write_max, 0644, show_dev_write_max_size, |
| 109 | + set_dev_write_max_size); |
| 110 | + static DEVICE_ATTR(dev_class, 0644, show_dev_class, set_dev_class); |
| 111 | +@@ -969,6 +1006,7 @@ static struct attribute *optoe_attrs[] = { |
| 112 | + #ifndef EEPROM_CLASS |
| 113 | + &dev_attr_port_name.attr, |
| 114 | + #endif |
| 115 | ++ &dev_attr_write_timeout.attr, |
| 116 | + &dev_attr_write_max.attr, |
| 117 | + &dev_attr_dev_class.attr, |
| 118 | + NULL, |
| 119 | +@@ -1079,6 +1117,7 @@ static int optoe_probe(struct i2c_client *client, |
| 120 | + optoe->use_smbus = use_smbus; |
| 121 | + optoe->chip = chip; |
| 122 | + optoe->num_addresses = num_addresses; |
| 123 | ++ optoe->write_timeout = OPTOE_DEFAULT_WRITE_TIMEOUT; |
| 124 | + memcpy(optoe->port_name, port_name, MAX_PORT_NAME_LEN); |
| 125 | + |
| 126 | + /* |
| 127 | +-- |
| 128 | +2.25.1 |
| 129 | + |
0 commit comments