1 From 0d035bed2a4a6c4878518749348be61bf082d12a Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Wed, 9 Dec 2020 11:22:49 +0000
4 Subject: [PATCH] net: sfp: VSOL V2801F / CarlitoxxPro CPGOS03-0490 v2.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 Add a workaround for the detection of VSOL V2801F / CarlitoxxPro
11 CPGOS03-0490 v2.0 GPON module which CarlitoxxPro states needs single
12 byte I2C reads to the EEPROM.
14 Pali Rohár reports that he also has a CarlitoxxPro-based V2801F module,
15 which reports a manufacturer of "OEM". This manufacturer can't be
16 matched as it appears in many different modules, so also match the part
19 Reported-by: Thomas Schreiber <tschreibe@gmail.com>
20 Reported-by: Pali Rohár <pali@kernel.org>
21 Tested-by: Pali Rohár <pali@kernel.org>
22 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
23 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
24 Signed-off-by: David S. Miller <davem@davemloft.net>
26 drivers/net/phy/sfp.c | 63 +++++++++++++++++++++++++++++++++++++++----
27 1 file changed, 58 insertions(+), 5 deletions(-)
29 --- a/drivers/net/phy/sfp.c
30 +++ b/drivers/net/phy/sfp.c
31 @@ -191,6 +191,7 @@ struct sfp {
32 struct sfp_bus *sfp_bus;
33 struct phy_device *mod_phy;
34 const struct sff_data *type;
35 + size_t i2c_block_size;
38 unsigned int (*get_state)(struct sfp *);
39 @@ -305,10 +306,19 @@ static int sfp_i2c_read(struct sfp *sfp,
42 struct i2c_msg msgs[2];
43 - u8 bus_addr = a2 ? 0x51 : 0x50;
53 + block_size = sfp->i2c_block_size;
57 msgs[0].addr = bus_addr;
60 @@ -320,8 +330,8 @@ static int sfp_i2c_read(struct sfp *sfp,
66 + if (this_len > block_size)
67 + this_len = block_size;
69 msgs[1].len = this_len;
71 @@ -1569,6 +1579,28 @@ static int sfp_sm_mod_hpower(struct sfp
75 +/* Some modules (Nokia 3FE46541AA) lock up if byte 0x51 is read as a
76 + * single read. Switch back to reading 16 byte blocks unless we have
77 + * a CarlitoxxPro module (rebranded VSOL V2801F). Even more annoyingly,
78 + * some VSOL V2801F have the vendor name changed to OEM.
80 +static int sfp_quirk_i2c_block_size(const struct sfp_eeprom_base *base)
82 + if (!memcmp(base->vendor_name, "VSOL ", 16))
84 + if (!memcmp(base->vendor_name, "OEM ", 16) &&
85 + !memcmp(base->vendor_pn, "V2801F ", 16))
88 + /* Some modules can't cope with long reads */
92 +static void sfp_quirks_base(struct sfp *sfp, const struct sfp_eeprom_base *base)
94 + sfp->i2c_block_size = sfp_quirk_i2c_block_size(base);
97 static int sfp_sm_mod_probe(struct sfp *sfp, bool report)
99 /* SFP module inserted - read I2C data */
100 @@ -1577,14 +1609,20 @@ static int sfp_sm_mod_probe(struct sfp *
104 - ret = sfp_read(sfp, false, 0, &id, sizeof(id));
105 + /* Some modules (CarlitoxxPro CPGOS03-0490) do not support multibyte
106 + * reads from the EEPROM, so start by reading the base identifying
107 + * information one byte at a time.
109 + sfp->i2c_block_size = 1;
111 + ret = sfp_read(sfp, false, 0, &id.base, sizeof(id.base));
114 dev_err(sfp->dev, "failed to read EEPROM: %d\n", ret);
118 - if (ret != sizeof(id)) {
119 + if (ret != sizeof(id.base)) {
120 dev_err(sfp->dev, "EEPROM short read: %d\n", ret);
123 @@ -1612,6 +1650,21 @@ static int sfp_sm_mod_probe(struct sfp *
127 + /* Apply any early module-specific quirks */
128 + sfp_quirks_base(sfp, &id.base);
130 + ret = sfp_read(sfp, false, SFP_CC_BASE + 1, &id.ext, sizeof(id.ext));
133 + dev_err(sfp->dev, "failed to read EEPROM: %d\n", ret);
137 + if (ret != sizeof(id.ext)) {
138 + dev_err(sfp->dev, "EEPROM short read: %d\n", ret);
142 check = sfp_check(&id.ext, sizeof(id.ext) - 1);
143 if (check != id.ext.cc_ext) {