Skip to contentSkip to conversation

eeprom/optoe: driver to read/write SFP/QSFP/CMIS EEPROMS

PATCH Superseded Don Bollinger 2 participants 3 messages Feb 15, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eeprom/optoe: driver to read/write SFP/QSFP/CMIS EEPROMS

optoe is an i2c based driver that supports read/write access to all the pages (tables) of MSA standard SFP and similar devices (conforming to the SFF-8472 spec), MSA standard QSFP and similar devices (conforming to the SFF-8636 spec) and CMIS and similar devices (conforming to the Common Management Interface Specfication).

These devices provide identification, operational status and control registers via an EEPROM model. These devices support one or 3 fixed pages (128 bytes) of data, and one page that is selected via a page register on the first fixed page. Thus the driver's main task is to map these pages onto a simple linear address space for user space management applications. See the driver code for a detailed layout.

Several variants and predecessors of this driver exist outside the kernel tree. Some of them don't support pages at all, only accessing the first 256 bytes of EEPROM. None of them handle all three specifications, none of them support pages beyond page 3. This is a problem since critical monitoring data on CMIS devices is on page 0x11. Some of them don't support pages at all, only accessing the first 256 bytes of data. optoe supports the full architected 256 page address space of these devices. optoe is currently in production on multiple platforms running SONiC (Microsoft's Software for Open Networking in the Cloud) and ONL (Open Network Linux). They have requested that optoe be submitted upstream.

The EEPROM data is accessible to user space and kernel consumers via the nvmem interface.

optoe devices can be configured via device tree or the 'new_device' paradigm.

See Documentation/misc-devices/optoe.rst for details on configuring optoe and accessing the EEPROM.

---
 Documentation/devicetree/bindings/eeprom/optoe.txt |  26 +
 Documentation/misc-devices/optoe.rst               | 127 +++
 drivers/misc/eeprom/Kconfig                        |  24 +
 drivers/misc/eeprom/Makefile                       |   1 +
 drivers/misc/eeprom/optoe.c                        | 931 +++++++++++++++++++++
 5 files changed, 1109 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/eeprom/optoe.txt
 create mode 100644 Documentation/misc-devices/optoe.rst
 create mode 100644 drivers/misc/eeprom/optoe.c
Documentation/devicetree/bindings/eeprom/optoe.txt new file +26 -0
new file mode 100644
index 000000000000..3a8c350cf2f5
@@ -0,0 +1,26 @@
+EEPROMs on SFP/QSFP/CMIS optoelectronic modules using SFF-8472, SFF-8676,
+CMIS (Common Management Interface Spec) devices.
+
+Required properties:
+- compatible: shall be one of : 
+	'optoe,optoe1' - for QSFP class devices, adhering to SFF-8636
+	'optoe,optoe2' - for SFP class devices, adhering to SFF-8472
+	'optoe,optoe3' - for CMIS devices (newer QSFP class devices)
+- reg: 0x50  The only valid value is 0x50, as all three standards specify that
+  the device is at i2c address 0x50.  (optoe allocates an i2c dummy to access
+  the data at i2c address 0x51.)
+
+Optional property:
+- port_name: can be set to any string up to 19 characters.  Note that the
+  actual mapping between i2c busses and network ports is platform dependent
+  and varies widely.  The 'port_name' property provides a way to associate
+  specific network ports with their associated hardware ports.
+
+Example:
+	#address-cells = <1>;
+	#size-cells = <0>;
+	optoe@50 {
+		compatible = "optoe,optoe2";
+		reg = <0x50>;
+		port_name = "port1";
+	};
Documentation/misc-devices/optoe.rst new file +127 -0

127 lines not on this page · raw message

drivers/misc/eeprom/Kconfig +24 -0
index 0f791bfdc1f5..17911266d3f6 100644
@@ -129,4 +129,28 @@ config EEPROM_EE1004
 	  This driver can also be built as a module.  If so, the module
 	  will be called ee1004.
 
+config EEPROM_OPTOE
+	tristate "read/write access to SFP*, QSFP* and CMIS EEPROMs"
+	depends on I2C && SYSFS
+	select NVMEM
+	select NVMEM_SYSFS
+	select REGMAP_I2C
+	help
+	  If you say yes here you get support for read and write access to
+	  the EEPROM of SFP, QSFP and CMIS type optical and copper
+	  transceivers.  This includes all devices which conform to SFF-8436
+	  and SFF-8636 (QSFP, QSFP+, QSFP28, etc), SFF-8472 (SFP, SFP+, SFP28,
+	  SFP-DWDM, etc) and Common Management Interface Spec (CMIS, including
+	  QSFP-DD, OSFP, later QSFP*, etc).
+
+	  These devices are usually found in network switches.
+
+	  This driver only manages read/write access to the EEPROM.  Access
+	  to the I/O pins (reset, LPMODE, etc) is still platform specific.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called optoe.
+
+	  If unsure, say N.
+
 endmenu
drivers/misc/eeprom/Makefile +1 -0
index a9b4b6579b75..e22ef2c05896 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_EEPROM_93XX46)	+= eeprom_93xx46.o
 obj-$(CONFIG_EEPROM_DIGSY_MTC_CFG) += digsy_mtc_eeprom.o
 obj-$(CONFIG_EEPROM_IDT_89HPESX) += idt_89hpesx.o
 obj-$(CONFIG_EEPROM_EE1004)	+= ee1004.o
+obj-$(CONFIG_EEPROM_OPTOE)	+= optoe.o
drivers/misc/eeprom/optoe.c new file +931 -0

931 lines not on this page · raw message

base-commit: a2ea4e1d9091cd8bc69f1c42c15bedc38618f04c

Signature · 1 line
2.11.0
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi Don,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on a2ea4e1d9091cd8bc69f1c42c15bedc38618f04c]

url:    https://github.com/0day-ci/linux/commits/Don-Bollinger/eeprom-optoe-driver-to-read-write-SFP-QSFP-CMIS-EEPROMS/20210215-083817
base:   a2ea4e1d9091cd8bc69f1c42c15bedc38618f04c
config: riscv-randconfig-r001-20210215 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c9439ca36342fb6013187d0a69aef92736951476)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/9089aa757bfb70c473ca54face762582908bdd28
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Don-Bollinger/eeprom-optoe-driver-to-read-write-SFP-QSFP-CMIS-EEPROMS/20210215-083817 git checkout 9089aa757bfb70c473ca54face762582908bdd28
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=riscv

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/misc/eeprom/optoe.c:615:16: warning: no previous prototype for function 'optoe_make_regmap' [-Wmissing-prototypes]
   struct regmap *optoe_make_regmap(struct i2c_client *client)
                  ^

drivers/misc/eeprom/optoe.c:615:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct regmap *optoe_make_regmap(struct i2c_client *client)
^
static
1 warning generated.

vim +/optoe_make_regmap +615 drivers/misc/eeprom/optoe.c

605
606
607 /*
608 * optoe_make_regmap creates the regmap for the client.
609 * IMPORTANT: Don't call the regmap read/write calls directly
610 * for these devices. These devices are paged, and you have to
611 * set the page register before accessing the data in that page.
612 * Use the nvmem interfaces, those read/write calls use this
613 * driver to manage pages correctly.
614 */

 > 615	struct regmap *optoe_make_regmap(struct i2c_client *client)

616 {
617 struct regmap_config regmap_config = { };
618 struct regmap *regmap;
619
620 /* setup a minimal regmap - 8 bits, 8 bit addresses */
621 regmap_config.val_bits = 8;
622 regmap_config.reg_bits = 8;
623
624 /* I'll handle the locking */
625 regmap_config.disable_locking = true;
626 regmap = devm_regmap_init_i2c(client, &regmap_config);
627 return regmap;
628 }
629

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Don Bollinger
Thank you for the patch! Perhaps something to improve:

Hi Don,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on a2ea4e1d9091cd8bc69f1c42c15bedc38618f04c]

url:    https://github.com/0day-ci/linux/commits/Don-Bollinger/eeprom-optoe-driver-to-read-write-SFP-QSFP-CMIS-EEPROMS/20210215-083817
base:   a2ea4e1d9091cd8bc69f1c42c15bedc38618f04c
config: sparc64-randconfig-p002-20210215 (attached as .config)
compiler: sparc64-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/9089aa757bfb70c473ca54face762582908bdd28
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Don-Bollinger/eeprom-optoe-driver-to-read-write-SFP-QSFP-CMIS-EEPROMS/20210215-083817 git checkout 9089aa757bfb70c473ca54face762582908bdd28
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sparc64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/misc/eeprom/optoe.c:615:16: warning: no previous prototype for 'optoe_make_regmap' [-Wmissing-prototypes]

615 | struct regmap *optoe_make_regmap(struct i2c_client *client)
| ^~~~~~~~~~~~~~~~~

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for COMPAT_BINFMT_ELF Depends on COMPAT && BINFMT_ELF
Selected by
- COMPAT && SPARC64

vim +/optoe_make_regmap +615 drivers/misc/eeprom/optoe.c

605
606
607 /*
608 * optoe_make_regmap creates the regmap for the client.
609 * IMPORTANT: Don't call the regmap read/write calls directly
610 * for these devices. These devices are paged, and you have to
611 * set the page register before accessing the data in that page.
612 * Use the nvmem interfaces, those read/write calls use this
613 * driver to manage pages correctly.
614 */

 > 615	struct regmap *optoe_make_regmap(struct i2c_client *client)

616 {
617 struct regmap_config regmap_config = { };
618 struct regmap *regmap;
619
620 /* setup a minimal regmap - 8 bits, 8 bit addresses */
621 regmap_config.val_bits = 8;
622 regmap_config.reg_bits = 8;
623
624 /* I'll handle the locking */
625 regmap_config.disable_locking = true;
626 regmap = devm_regmap_init_i2c(client, &regmap_config);
627 return regmap;
628 }
629

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org