1- From 526a41f1fc717ddb6cfd600c899254d582735523 Mon Sep 17 00:00:00 2001
1+ From 0020c4e2164d6b645ce571dc20137266c195012f Mon Sep 17 00:00:00 2001
22From: Wataru Ishida <wataru.ishid@gmail.com>
33Date: Sun, 15 Feb 2026 22:34:29 +0900
44Subject: [PATCH] optoe: Add CMIS Bank support for transceivers with >8 lanes
@@ -13,11 +13,11 @@ to enable access to CMIS transceivers with more than 8 lanes (e.g., OSFP-XD, CPO
1313Signed-off-by: Wataru Ishida <wataru.ishid@gmail.com>
1414
1515---
16- drivers/misc/eeprom/optoe.c | 194 +++++++++++++++++++++++++++++++-----
17- 1 file changed, 167 insertions(+), 27 deletions(-)
16+ drivers/misc/eeprom/optoe.c | 197 +++++++++++++++++++++++++++++++-----
17+ 1 file changed, 170 insertions(+), 27 deletions(-)
1818
1919diff --git a/drivers/misc/eeprom/optoe.c b/drivers/misc/eeprom/optoe.c
20- index ba4ca17..8ba71ef 100644
20+ index ba4ca17..14b60d9 100644
2121--- a/drivers/misc/eeprom/optoe.c
2222+++ b/drivers/misc/eeprom/optoe.c
2323@@ -101,9 +101,50 @@
@@ -165,7 +165,7 @@ index ba4ca17..8ba71ef 100644
165165 }
166166
167167 static ssize_t optoe_eeprom_read(struct optoe_data *optoe,
168- @@ -511,23 +581,41 @@ static ssize_t optoe_eeprom_update_client(struct optoe_data *optoe,
168+ @@ -511,23 +581,44 @@ static ssize_t optoe_eeprom_update_client(struct optoe_data *optoe,
169169 {
170170 struct i2c_client *client;
171171 ssize_t retval = 0;
@@ -198,8 +198,11 @@ index ba4ca17..8ba71ef 100644
198198+ */
199199+ if (bank > 0) {
200200+ char buf[2] = {bank, page};
201+ + unsigned int write_max_orig = optoe->write_max;
202+ + optoe->write_max = 2; /* ensure both bank and page are written together */
201203+ ret = optoe_eeprom_write(optoe, client, buf,
202204+ OPTOE_BANK_SELECT_REG, 2);
205+ + optoe->write_max = write_max_orig;
203206+ } else {
204207+ ret = optoe_eeprom_write(optoe, client, &page,
205208+ OPTOE_PAGE_SELECT_REG, 1);
@@ -216,7 +219,7 @@ index ba4ca17..8ba71ef 100644
216219 }
217220
218221 while (count) {
219- @@ -553,13 +641,20 @@ static ssize_t optoe_eeprom_update_client(struct optoe_data *optoe,
222+ @@ -553,13 +644,23 @@ static ssize_t optoe_eeprom_update_client(struct optoe_data *optoe,
220223
221224
222225 if (page > 0) {
@@ -226,8 +229,11 @@ index ba4ca17..8ba71ef 100644
226229- OPTOE_PAGE_SELECT_REG, 1);
227230+ if (bank > 0) {
228231+ char buf[2] = {0, 0};
232+ + unsigned int write_max_orig = optoe->write_max;
233+ + optoe->write_max = 2; /* ensure both bank and page are written together */
229234+ ret = optoe_eeprom_write(optoe, client, buf,
230235+ OPTOE_BANK_SELECT_REG, 2);
236+ + optoe->write_max = write_max_orig;
231237+ } else {
232238+ page = 0;
233239+ ret = optoe_eeprom_write(optoe, client, &page,
@@ -242,7 +248,7 @@ index ba4ca17..8ba71ef 100644
242248 /* error only if nothing has been transferred */
243249 if (retval == 0)
244250 retval = ret;
245- @@ -622,8 +717 ,10 @@ static ssize_t optoe_page_legal(struct optoe_data *optoe,
251+ @@ -622,8 +723 ,10 @@ static ssize_t optoe_page_legal(struct optoe_data *optoe,
246252 /* if no pages needed, we're good */
247253 if ((off + len) <= ONE_ADDR_EEPROM_UNPAGED_SIZE)
248254 return len;
@@ -254,7 +260,7 @@ index ba4ca17..8ba71ef 100644
254260 return OPTOE_EOF;
255261 /* in between, are pages supported? */
256262 status = optoe_eeprom_read(optoe, client, ®val,
257- @@ -665,7 +762 ,7 @@ static ssize_t optoe_page_legal(struct optoe_data *optoe,
263+ @@ -665,7 +768 ,7 @@ static ssize_t optoe_page_legal(struct optoe_data *optoe,
258264 maxlen = ONE_ADDR_EEPROM_UNPAGED_SIZE - off;
259265 } else {
260266 /* Pages supported, trim len to the end of pages */
@@ -263,7 +269,7 @@ index ba4ca17..8ba71ef 100644
263269 }
264270 len = (len > maxlen) ? maxlen : len;
265271 dev_dbg(&client->dev,
266- @@ -995,6 +1092,47 @@ static ssize_t set_port_name(struct device *dev,
272+ @@ -995,6 +1098,44 @@ static ssize_t set_port_name(struct device *dev,
267273 return count;
268274 }
269275
@@ -300,9 +306,6 @@ index ba4ca17..8ba71ef 100644
300306+
301307+ mutex_lock(&optoe->lock);
302308+ optoe->bank_size = bank_size;
303- + if (optoe->bank_size > 0 && optoe->write_max == 1) {
304- + optoe->write_max = 2;
305- + }
306309+ mutex_unlock(&optoe->lock);
307310+
308311+ return count;
@@ -311,31 +314,31 @@ index ba4ca17..8ba71ef 100644
311314 static DEVICE_ATTR(port_name, 0644, show_port_name, set_port_name);
312315 #endif /* if NOT defined EEPROM_CLASS, the common case */
313316
314- @@ -1003,6 +1141 ,7 @@ static DEVICE_ATTR(write_timeout, 0644, show_dev_write_timeout_size,
317+ @@ -1003,6 +1144 ,7 @@ static DEVICE_ATTR(write_timeout, 0644, show_dev_write_timeout_size,
315318 static DEVICE_ATTR(write_max, 0644, show_dev_write_max_size,
316319 set_dev_write_max_size);
317320 static DEVICE_ATTR(dev_class, 0644, show_dev_class, set_dev_class);
318321+ static DEVICE_ATTR(bank_size, 0644, show_bank_size, set_bank_size);
319322
320323 static struct attribute *optoe_attrs[] = {
321324 #ifndef EEPROM_CLASS
322- @@ -1011,6 +1150 ,7 @@ static struct attribute *optoe_attrs[] = {
325+ @@ -1011,6 +1153 ,7 @@ static struct attribute *optoe_attrs[] = {
323326 &dev_attr_write_timeout.attr,
324327 &dev_attr_write_max.attr,
325328 &dev_attr_dev_class.attr,
326329+ &dev_attr_bank_size.attr,
327330 NULL,
328331 };
329332
330- @@ -1027,7 +1167 ,6 @@ static int optoe_probe(struct i2c_client *client)
333+ @@ -1027,7 +1170 ,6 @@ static int optoe_probe(struct i2c_client *client)
331334 const struct i2c_device_id *id;
332335 int num_addresses = 0;
333336 char port_name[MAX_PORT_NAME_LEN];
334337-
335338 if (client->addr != 0x50) {
336339 dev_dbg(&client->dev, "probe, bad i2c addr: 0x%x\n",
337340 client->addr);
338- @@ -1109,7 +1248 ,7 @@ static int optoe_probe(struct i2c_client *client)
341+ @@ -1109,7 +1251 ,7 @@ static int optoe_probe(struct i2c_client *client)
339342 } else if (strcmp(client->name, "optoe3") == 0) {
340343 /* CMIS spec */
341344 optoe->dev_class = CMIS_ADDR;
@@ -344,7 +347,7 @@ index ba4ca17..8ba71ef 100644
344347 num_addresses = 1;
345348 } else { /* those were the only choices */
346349 err = -EINVAL;
347- @@ -1121,6 +1260 ,7 @@ static int optoe_probe(struct i2c_client *client)
350+ @@ -1121,6 +1263 ,7 @@ static int optoe_probe(struct i2c_client *client)
348351 optoe->chip = chip;
349352 optoe->num_addresses = num_addresses;
350353 optoe->write_timeout = OPTOE_DEFAULT_WRITE_TIMEOUT;
0 commit comments