Skip to content

Commit 1b2fb60

Browse files
committed
fix(optoe): add explanation for bank page support
Signed-off-by: Wataru Ishida <wataru.ishid@gmail.com>
1 parent 4f10614 commit 1b2fb60

1 file changed

Lines changed: 69 additions & 20 deletions

File tree

patch/driver-support-optoe-bank-support.patch

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From b1a63f047615b56c271e6d41e50112045fd6a978 Mon Sep 17 00:00:00 2001
1+
From aa39d1af8ae72a7a3f6f5337266d69f720a39086 Mon Sep 17 00:00:00 2001
22
From: Wataru Ishida <wataru.ishid@gmail.com>
33
Date: Wed, 2 Apr 2025 07:10:10 +0000
44
Subject: [PATCH] optoe: Add CMIS Bank support for transceivers with >8 lanes
@@ -16,18 +16,67 @@ to enable access to CMIS transceivers with more than 8 lanes (e.g., OSFP-XD, CPO
1616

1717
Signed-off-by: Wataru Ishida <wataru.ishid@gmail.com>
1818
---
19-
drivers/misc/eeprom/optoe.c | 124 ++++++++++++++++++++++++++++++------
20-
1 file changed, 103 insertions(+), 21 deletions(-)
19+
drivers/misc/eeprom/optoe.c | 165 +++++++++++++++++++++++++++++++-----
20+
1 file changed, 142 insertions(+), 23 deletions(-)
2121

2222
diff --git a/drivers/misc/eeprom/optoe.c b/drivers/misc/eeprom/optoe.c
23-
index 22d2c0cd4..71bd90204 100644
23+
index 22d2c0cd4..a4def4986 100644
2424
--- a/drivers/misc/eeprom/optoe.c
2525
+++ b/drivers/misc/eeprom/optoe.c
26-
@@ -150,6 +150,12 @@ struct optoe_platform_data {
26+
@@ -101,9 +101,42 @@
27+
* considerably more pages (at least to page 0xAF), which this driver
28+
* supports.
29+
*
30+
- * NOTE: This version of the driver ONLY SUPPORTS BANK 0 PAGES on CMIS
31+
- * devices.
32+
+ * For CMIS transceivers that support Banked Pages, access to these pages
33+
+ * is also supported. To access the banked pages, set the number of banks
34+
+ * to access via the `bank_size` sysfs entry.
35+
+ * By default, `bank_size` is set to 0, which disables this feature.
36+
*
37+
+ * The maximum number of banks supported in this version is 8.
38+
+ *
39+
+ * When access to the Banked Pages is enabled, they are mapped into a linear
40+
+ * address space. The mapping starts right after the Non-Banked Page area,
41+
+ * as shown below.
42+
+ *
43+
+ * +-------------------------------+
44+
+ * | Lower Page |
45+
+ * +-------------------------------+
46+
+ * | Upper Page (Bank 0, Page 0h) |
47+
+ * +-------------------------------+
48+
+ * | Upper Page (Bank 0, Page 1h) |
49+
+ * +-------------------------------+
50+
+ * | ... |
51+
+ * +-------------------------------+
52+
+ * | Upper Page (Bank 0, Page FFh) |
53+
+ * +-------------------------------+
54+
+ * | Upper Page (Bank 1, Page 10h) |
55+
+ * +-------------------------------+
56+
+ * | ... |
57+
+ * +-------------------------------+
58+
+ * | Upper Page (Bank 1, Page FFh) |
59+
+ * +-------------------------------+
60+
+ * | Upper Page (Bank 2, Page 10h) |
61+
+ * +-------------------------------+
62+
+ * | ... |
63+
+ * +-------------------------------+
64+
+ * | Upper Page (Bank 2, Page FFh) |
65+
+ * +-------------------------------+
66+
+ * | ... |
67+
+ * (continued for more banks)
68+
**/
69+
70+
/* #define DEBUG 1 */
71+
@@ -150,6 +183,16 @@ struct optoe_platform_data {
2772

2873
/* fundamental unit of addressing for EEPROM */
2974
#define OPTOE_PAGE_SIZE 128
3075
+
76+
+/*
77+
+ *
78+
+ *
79+
+ */
3180
+#define OPTOE_DEFAULT_BANK_SIZE 0
3281
+#define OPTOE_MAX_SUPPORTED_BANK_SIZE 8
3382
+#define OPTOE_NON_BANKED_PAGE_SIZE 16 /* page 00h-0Fh are not banked */
@@ -36,23 +85,23 @@ index 22d2c0cd4..71bd90204 100644
3685
/*
3786
* Single address devices (eg QSFP) have 256 pages, plus the unpaged
3887
* low 128 bytes. If the device does not support paging, it is
39-
@@ -168,6 +174,7 @@ struct optoe_platform_data {
88+
@@ -168,6 +211,7 @@ struct optoe_platform_data {
4089
#define TWO_ADDR_NO_0X51_SIZE (2 * OPTOE_PAGE_SIZE)
4190

4291
/* a few constants to find our way around the EEPROM */
4392
+#define OPTOE_BANK_SELECT_REG 0x7E
4493
#define OPTOE_PAGE_SELECT_REG 0x7F
4594
#define ONE_ADDR_PAGEABLE_REG 0x02
4695
#define QSFP_NOT_PAGEABLE (1<<2)
47-
@@ -195,6 +202,7 @@ struct optoe_data {
96+
@@ -195,6 +239,7 @@ struct optoe_data {
4897
u8 *writebuf;
4998
unsigned int write_max;
5099
unsigned int write_timeout;
51100
+ unsigned int bank_size; /* 0 means bank is not supported */
52101

53102
unsigned int num_addresses;
54103

55-
@@ -245,13 +253,19 @@ static const struct i2c_device_id optoe_ids[] = {
104+
@@ -245,13 +290,19 @@ static const struct i2c_device_id optoe_ids[] = {
56105
};
57106
MODULE_DEVICE_TABLE(i2c, optoe_ids);
58107

@@ -73,7 +122,7 @@ index 22d2c0cd4..71bd90204 100644
73122
*
74123
* Handles both single address (eg QSFP) and two address (eg SFP).
75124
* For SFP, offset 0-255 are on client[0], >255 is on client[1]
76-
@@ -274,7 +288,7 @@ MODULE_DEVICE_TABLE(i2c, optoe_ids);
125+
@@ -274,7 +325,7 @@ MODULE_DEVICE_TABLE(i2c, optoe_ids);
77126
*/
78127

79128
static uint8_t optoe_translate_offset(struct optoe_data *optoe,
@@ -82,7 +131,7 @@ index 22d2c0cd4..71bd90204 100644
82131
{
83132
unsigned int page = 0;
84133

85-
@@ -301,8 +315,9 @@ static uint8_t optoe_translate_offset(struct optoe_data *optoe,
134+
@@ -301,8 +352,9 @@ static uint8_t optoe_translate_offset(struct optoe_data *optoe,
86135
page = (*offset >> 7)-1;
87136
/* 0x80 places the offset in the top half, offset is last 7 bits */
88137
*offset = OPTOE_PAGE_SIZE + (*offset & 0x7f);
@@ -94,7 +143,7 @@ index 22d2c0cd4..71bd90204 100644
94143
}
95144

96145
static ssize_t optoe_eeprom_read(struct optoe_data *optoe,
97-
@@ -511,21 +526,38 @@ static ssize_t optoe_eeprom_update_client(struct optoe_data *optoe,
146+
@@ -511,21 +563,38 @@ static ssize_t optoe_eeprom_update_client(struct optoe_data *optoe,
98147
{
99148
struct i2c_client *client;
100149
ssize_t retval = 0;
@@ -141,7 +190,7 @@ index 22d2c0cd4..71bd90204 100644
141190
return ret;
142191
}
143192
}
144-
@@ -553,13 +585,18 @@ static ssize_t optoe_eeprom_update_client(struct optoe_data *optoe,
193+
@@ -553,13 +622,18 @@ static ssize_t optoe_eeprom_update_client(struct optoe_data *optoe,
145194

146195

147196
if (page > 0) {
@@ -165,7 +214,7 @@ index 22d2c0cd4..71bd90204 100644
165214
/* error only if nothing has been transferred */
166215
if (retval == 0)
167216
retval = ret;
168-
@@ -622,8 +659,10 @@ static ssize_t optoe_page_legal(struct optoe_data *optoe,
217+
@@ -622,8 +696,10 @@ static ssize_t optoe_page_legal(struct optoe_data *optoe,
169218
/* if no pages needed, we're good */
170219
if ((off + len) <= ONE_ADDR_EEPROM_UNPAGED_SIZE)
171220
return len;
@@ -177,7 +226,7 @@ index 22d2c0cd4..71bd90204 100644
177226
return OPTOE_EOF;
178227
/* in between, are pages supported? */
179228
status = optoe_eeprom_read(optoe, client, &regval,
180-
@@ -665,7 +704,7 @@ static ssize_t optoe_page_legal(struct optoe_data *optoe,
229+
@@ -665,7 +741,7 @@ static ssize_t optoe_page_legal(struct optoe_data *optoe,
181230
maxlen = ONE_ADDR_EEPROM_UNPAGED_SIZE - off;
182231
} else {
183232
/* Pages supported, trim len to the end of pages */
@@ -186,7 +235,7 @@ index 22d2c0cd4..71bd90204 100644
186235
}
187236
len = (len > maxlen) ? maxlen : len;
188237
dev_dbg(&client->dev,
189-
@@ -995,6 +1034,47 @@ static ssize_t set_port_name(struct device *dev,
238+
@@ -995,6 +1071,47 @@ static ssize_t set_port_name(struct device *dev,
190239
return count;
191240
}
192241

@@ -234,31 +283,31 @@ index 22d2c0cd4..71bd90204 100644
234283
static DEVICE_ATTR(port_name, 0644, show_port_name, set_port_name);
235284
#endif /* if NOT defined EEPROM_CLASS, the common case */
236285

237-
@@ -1003,6 +1083,7 @@ static DEVICE_ATTR(write_timeout, 0644, show_dev_write_timeout_size,
286+
@@ -1003,6 +1120,7 @@ static DEVICE_ATTR(write_timeout, 0644, show_dev_write_timeout_size,
238287
static DEVICE_ATTR(write_max, 0644, show_dev_write_max_size,
239288
set_dev_write_max_size);
240289
static DEVICE_ATTR(dev_class, 0644, show_dev_class, set_dev_class);
241290
+static DEVICE_ATTR(bank_size, 0644, show_bank_size, set_bank_size);
242291

243292
static struct attribute *optoe_attrs[] = {
244293
#ifndef EEPROM_CLASS
245-
@@ -1011,6 +1092,7 @@ static struct attribute *optoe_attrs[] = {
294+
@@ -1011,6 +1129,7 @@ static struct attribute *optoe_attrs[] = {
246295
&dev_attr_write_timeout.attr,
247296
&dev_attr_write_max.attr,
248297
&dev_attr_dev_class.attr,
249298
+ &dev_attr_bank_size.attr,
250299
NULL,
251300
};
252301

253-
@@ -1027,7 +1109,6 @@ static int optoe_probe(struct i2c_client *client,
302+
@@ -1027,7 +1146,6 @@ static int optoe_probe(struct i2c_client *client,
254303
struct optoe_data *optoe;
255304
int num_addresses = 0;
256305
char port_name[MAX_PORT_NAME_LEN];
257306
-
258307
if (client->addr != 0x50) {
259308
dev_dbg(&client->dev, "probe, bad i2c addr: 0x%x\n",
260309
client->addr);
261-
@@ -1108,7 +1189,7 @@ static int optoe_probe(struct i2c_client *client,
310+
@@ -1108,7 +1226,7 @@ static int optoe_probe(struct i2c_client *client,
262311
} else if (strcmp(client->name, "optoe3") == 0) {
263312
/* CMIS spec */
264313
optoe->dev_class = CMIS_ADDR;
@@ -267,7 +316,7 @@ index 22d2c0cd4..71bd90204 100644
267316
num_addresses = 1;
268317
} else { /* those were the only choices */
269318
err = -EINVAL;
270-
@@ -1120,6 +1201,7 @@ static int optoe_probe(struct i2c_client *client,
319+
@@ -1120,6 +1238,7 @@ static int optoe_probe(struct i2c_client *client,
271320
optoe->chip = chip;
272321
optoe->num_addresses = num_addresses;
273322
optoe->write_timeout = OPTOE_DEFAULT_WRITE_TIMEOUT;

0 commit comments

Comments
 (0)