1901054a100df0a59b97da4e9f04d53711962c1c
[openwrt/staging/ldir.git] /
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
5 workaround
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
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.
13
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
17 number too.
18
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>
25 ---
26 drivers/net/phy/sfp.c | 63 +++++++++++++++++++++++++++++++++++++++----
27 1 file changed, 58 insertions(+), 5 deletions(-)
28
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;
36 u32 max_power_mW;
37
38 unsigned int (*get_state)(struct sfp *);
39 @@ -305,10 +306,19 @@ static int sfp_i2c_read(struct sfp *sfp,
40 size_t len)
41 {
42 struct i2c_msg msgs[2];
43 - u8 bus_addr = a2 ? 0x51 : 0x50;
44 + size_t block_size;
45 size_t this_len;
46 + u8 bus_addr;
47 int ret;
48
49 + if (a2) {
50 + block_size = 16;
51 + bus_addr = 0x51;
52 + } else {
53 + block_size = sfp->i2c_block_size;
54 + bus_addr = 0x50;
55 + }
56 +
57 msgs[0].addr = bus_addr;
58 msgs[0].flags = 0;
59 msgs[0].len = 1;
60 @@ -320,8 +330,8 @@ static int sfp_i2c_read(struct sfp *sfp,
61
62 while (len) {
63 this_len = len;
64 - if (this_len > 16)
65 - this_len = 16;
66 + if (this_len > block_size)
67 + this_len = block_size;
68
69 msgs[1].len = this_len;
70
71 @@ -1569,6 +1579,28 @@ static int sfp_sm_mod_hpower(struct sfp
72 return 0;
73 }
74
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.
79 + */
80 +static int sfp_quirk_i2c_block_size(const struct sfp_eeprom_base *base)
81 +{
82 + if (!memcmp(base->vendor_name, "VSOL ", 16))
83 + return 1;
84 + if (!memcmp(base->vendor_name, "OEM ", 16) &&
85 + !memcmp(base->vendor_pn, "V2801F ", 16))
86 + return 1;
87 +
88 + /* Some modules can't cope with long reads */
89 + return 16;
90 +}
91 +
92 +static void sfp_quirks_base(struct sfp *sfp, const struct sfp_eeprom_base *base)
93 +{
94 + sfp->i2c_block_size = sfp_quirk_i2c_block_size(base);
95 +}
96 +
97 static int sfp_sm_mod_probe(struct sfp *sfp, bool report)
98 {
99 /* SFP module inserted - read I2C data */
100 @@ -1577,14 +1609,20 @@ static int sfp_sm_mod_probe(struct sfp *
101 u8 check;
102 int ret;
103
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.
108 + */
109 + sfp->i2c_block_size = 1;
110 +
111 + ret = sfp_read(sfp, false, 0, &id.base, sizeof(id.base));
112 if (ret < 0) {
113 if (report)
114 dev_err(sfp->dev, "failed to read EEPROM: %d\n", ret);
115 return -EAGAIN;
116 }
117
118 - if (ret != sizeof(id)) {
119 + if (ret != sizeof(id.base)) {
120 dev_err(sfp->dev, "EEPROM short read: %d\n", ret);
121 return -EAGAIN;
122 }
123 @@ -1612,6 +1650,21 @@ static int sfp_sm_mod_probe(struct sfp *
124 }
125 }
126
127 + /* Apply any early module-specific quirks */
128 + sfp_quirks_base(sfp, &id.base);
129 +
130 + ret = sfp_read(sfp, false, SFP_CC_BASE + 1, &id.ext, sizeof(id.ext));
131 + if (ret < 0) {
132 + if (report)
133 + dev_err(sfp->dev, "failed to read EEPROM: %d\n", ret);
134 + return -EAGAIN;
135 + }
136 +
137 + if (ret != sizeof(id.ext)) {
138 + dev_err(sfp->dev, "EEPROM short read: %d\n", ret);
139 + return -EAGAIN;
140 + }
141 +
142 check = sfp_check(&id.ext, sizeof(id.ext) - 1);
143 if (check != id.ext.cc_ext) {
144 if (cotsworks) {