1 From 559391fc20fae506adcb311b904cc544c76436c0 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Thu, 7 Nov 2019 18:52:07 +0000
4 Subject: [PATCH 634/660] net: sfp: allow modules with slow diagnostics to
7 When a module is inserted, we attempt to read read the ID from address
8 0x50. Once we are able to read the ID, we immediately attempt to
9 initialise the hwmon support by reading from address 0x51. If this
10 fails, then we fall into error state, and assume that the module is
13 Modules such as the ALCATELLUCENT 3FE46541AA use a real EEPROM for
14 I2C address 0x50, which responds immediately. However, address 0x51
15 is an emulated, which only becomes available once the on-board firmware
16 has booted. This prompts us to fall into the error state.
18 Since the module may be usable without diagnostics, arrange for the
19 hwmon probe independent of the rest of the SFP itself, retrying every
20 5s for up to about 60s for the monitoring to become available, and
21 print an error message if it doesn't become available.
23 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
25 drivers/net/phy/sfp.c | 96 +++++++++++++++++++++++++++++++++----------
26 1 file changed, 74 insertions(+), 22 deletions(-)
28 --- a/drivers/net/phy/sfp.c
29 +++ b/drivers/net/phy/sfp.c
30 @@ -216,6 +216,8 @@ struct sfp {
32 #if IS_ENABLED(CONFIG_HWMON)
34 + struct delayed_work hwmon_probe;
35 + unsigned int hwmon_tries;
36 struct device *hwmon_dev;
39 @@ -1094,29 +1096,27 @@ static const struct hwmon_chip_info sfp_
40 .info = sfp_hwmon_info,
43 -static int sfp_hwmon_insert(struct sfp *sfp)
44 +static void sfp_hwmon_probe(struct work_struct *work)
46 + struct sfp *sfp = container_of(work, struct sfp, hwmon_probe.work);
49 - if (sfp->id.ext.sff8472_compliance == SFP_SFF8472_COMPLIANCE_NONE)
52 - if (!(sfp->id.ext.diagmon & SFP_DIAGMON_DDM))
55 - if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)
56 - /* This driver in general does not support address
61 err = sfp_read(sfp, true, 0, &sfp->diag, sizeof(sfp->diag));
65 + if (sfp->hwmon_tries--) {
66 + mod_delayed_work(system_wq, &sfp->hwmon_probe,
67 + T_PROBE_RETRY_SLOW);
69 + dev_warn(sfp->dev, "hwmon probe failed: %d\n", err);
74 sfp->hwmon_name = kstrdup(dev_name(sfp->dev), GFP_KERNEL);
75 - if (!sfp->hwmon_name)
77 + if (!sfp->hwmon_name) {
78 + dev_err(sfp->dev, "out of memory for hwmon name\n");
82 for (i = 0; sfp->hwmon_name[i]; i++)
83 if (hwmon_is_bad_char(sfp->hwmon_name[i]))
84 @@ -1126,18 +1126,52 @@ static int sfp_hwmon_insert(struct sfp *
88 + if (IS_ERR(sfp->hwmon_dev))
89 + dev_err(sfp->dev, "failed to register hwmon device: %ld\n",
90 + PTR_ERR(sfp->hwmon_dev));
93 +static int sfp_hwmon_insert(struct sfp *sfp)
95 + if (sfp->id.ext.sff8472_compliance == SFP_SFF8472_COMPLIANCE_NONE)
98 + if (!(sfp->id.ext.diagmon & SFP_DIAGMON_DDM))
101 + if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)
102 + /* This driver in general does not support address
107 + mod_delayed_work(system_wq, &sfp->hwmon_probe, 1);
108 + sfp->hwmon_tries = R_PROBE_RETRY_SLOW;
110 - return PTR_ERR_OR_ZERO(sfp->hwmon_dev);
114 static void sfp_hwmon_remove(struct sfp *sfp)
116 + cancel_delayed_work_sync(&sfp->hwmon_probe);
117 if (!IS_ERR_OR_NULL(sfp->hwmon_dev)) {
118 hwmon_device_unregister(sfp->hwmon_dev);
119 sfp->hwmon_dev = NULL;
120 kfree(sfp->hwmon_name);
124 +static int sfp_hwmon_init(struct sfp *sfp)
126 + INIT_DELAYED_WORK(&sfp->hwmon_probe, sfp_hwmon_probe);
131 +static void sfp_hwmon_exit(struct sfp *sfp)
133 + cancel_delayed_work_sync(&sfp->hwmon_probe);
136 static int sfp_hwmon_insert(struct sfp *sfp)
138 @@ -1147,6 +1181,15 @@ static int sfp_hwmon_insert(struct sfp *
139 static void sfp_hwmon_remove(struct sfp *sfp)
143 +static int sfp_hwmon_init(struct sfp *sfp)
148 +static void sfp_hwmon_exit(struct sfp *sfp)
154 @@ -1483,10 +1526,6 @@ static int sfp_sm_mod_probe(struct sfp *
158 - ret = sfp_hwmon_insert(sfp);
165 @@ -1635,6 +1674,15 @@ static void sfp_sm_module(struct sfp *sf
170 +#if IS_ENABLED(CONFIG_HWMON)
171 + if (sfp->sm_mod_state >= SFP_MOD_WAITDEV &&
172 + IS_ERR_OR_NULL(sfp->hwmon_dev)) {
173 + err = sfp_hwmon_insert(sfp);
175 + dev_warn(sfp->dev, "hwmon probe failed: %d\n", err);
180 static void sfp_sm_main(struct sfp *sfp, unsigned int event)
181 @@ -1936,6 +1984,8 @@ static struct sfp *sfp_alloc(struct devi
182 INIT_DELAYED_WORK(&sfp->poll, sfp_poll);
183 INIT_DELAYED_WORK(&sfp->timeout, sfp_timeout);
185 + sfp_hwmon_init(sfp);
190 @@ -1943,6 +1993,8 @@ static void sfp_cleanup(void *data)
192 struct sfp *sfp = data;
194 + sfp_hwmon_exit(sfp);
196 cancel_delayed_work_sync(&sfp->poll);
197 cancel_delayed_work_sync(&sfp->timeout);