Skip to content

Commit 714d1ab

Browse files
SFP plugged in logs continuously printed for DAC SFP
NET:ETH:PHY:A2 might not be valid for A0 need to avoid SFP plugin log NET:ETH:PHY:rate limit the SFP plugin(out) log Co-authored-by: Narayan, Preetam <preetam.narayan@altera.com>
1 parent aae983b commit 714d1ab

File tree

3 files changed

+31
-2333
lines changed

3 files changed

+31
-2333
lines changed

drivers/net/phy/sfp-mem-core.c

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static ssize_t sfp_connected_show(struct device *dev, struct device_attribute *a
158158
bool plugin;
159159

160160
mutex_lock(&sfp->lock);
161-
plugin = check_sfp_plugin(sfp) && (sfp->init == SFP_INIT_DONE);
161+
plugin = check_sfp_plugin(sfp) && (sfp->state == SFP_INIT_DONE);
162162
mutex_unlock(&sfp->lock);
163163

164164
return sysfs_emit(buf, "%u\n", plugin);
@@ -201,28 +201,32 @@ static void sfp_check_hotplug(struct work_struct *work)
201201

202202
is_sfp_pluggedin = check_sfp_plugin(sfp);
203203

204-
if ((!is_sfp_pluggedin) && (sfp->init != SFP_INIT_RESET)) {
205-
dev_info(sfp->dev, "detected SFP unplugin\n");
206-
WRITE_ONCE(sfp->init, SFP_INIT_RESET);
204+
if ((!is_sfp_pluggedin) && (sfp->state != SFP_DETECT)) {
205+
dev_info_ratelimited(sfp->dev, "detected SFP plug out\n");
206+
WRITE_ONCE(sfp->state, SFP_DETECT);
207207
}
208208

209209
/* in case of error observed then we need to take defensive action */
210210
if (stat_off & A2_UPD_ERROR)
211-
WRITE_ONCE(sfp->init, SFP_A2_UPDATE_ERROR);
211+
WRITE_ONCE(sfp->state, SFP_A2_UPDATE_ERROR);
212212

213213
if (stat_off & A0_UPD_ERROR)
214-
WRITE_ONCE(sfp->init, SFP_A0_UPDATE_ERROR);
214+
WRITE_ONCE(sfp->state, SFP_A0_UPDATE_ERROR);
215215

216-
switch(sfp->init) {
216+
switch(sfp->state) {
217217

218-
case SFP_INIT_RESET:
218+
case SFP_DETECT:
219219
if (is_sfp_pluggedin) {
220-
dev_info(sfp->dev, "detected SFP plugin\n");
221-
if(sfp_init(sfp))
222-
WRITE_ONCE(sfp->init, SFP_INIT_DONE);
223-
sfp->tolerance_count = IP_RESPONSE_TOLERANCE_LIMIT;
220+
dev_info_ratelimited(sfp->dev, "detected SFP plugin\n");
221+
WRITE_ONCE(sfp->state, SFP_INIT_RESET);
224222
}
225223
break;
224+
225+
case SFP_INIT_RESET:
226+
if(sfp_init(sfp))
227+
WRITE_ONCE(sfp->state, SFP_INIT_DONE);
228+
sfp->tolerance_count = IP_RESPONSE_TOLERANCE_LIMIT;
229+
break;
226230

227231
case SFP_INIT_DONE:
228232
if (!(stat_off & A0_UPD_RDY_TO_START))
@@ -236,16 +240,17 @@ static void sfp_check_hotplug(struct work_struct *work)
236240
(stat_off & A0_UPD_IN_PROG)),
237241
10, I2C_MAX_TIMEOUT);
238242
if (!poll_timeout) {
239-
WRITE_ONCE(sfp->init, SFP_A0PAGE_UPDATE_INPROG);
243+
WRITE_ONCE(sfp->state, SFP_A0PAGE_UPDATE_INPROG);
240244
sfp->tolerance_count = IP_RESPONSE_TOLERANCE_LIMIT;
245+
break;
241246
} else {
242247
dev_warn_ratelimited(sfp->dev,
243248
"SFP FSM state change to SFP_A0PAGE_UPDATE_INPROG"
244249
"unexpected delay\n");
245250
}
246251

247252
if (--sfp->tolerance_count == IP_IRRESPONSIVE) {
248-
WRITE_ONCE(sfp->init, SFP_INIT_RESET);
253+
WRITE_ONCE(sfp->state, SFP_INIT_RESET);
249254
break;
250255
}
251256
}
@@ -266,35 +271,35 @@ static void sfp_check_hotplug(struct work_struct *work)
266271
*/
267272
writeq(sfp_sel, sfp->base + CONF_OFF);
268273

269-
WRITE_ONCE(sfp->init, SFP_A0PAGE_UPDATE_COMPLETE);
274+
WRITE_ONCE(sfp->state, SFP_A0PAGE_UPDATE_COMPLETE);
270275
}
271276
break;
272277

273278
case SFP_A0PAGE_UPDATE_COMPLETE:
274279

275280
writeq(CONF_POLL_EN, sfp->base + CONF_OFF);
276-
WRITE_ONCE(sfp->init, SFP_A2PAGE_UPDATE_INPROG);
281+
WRITE_ONCE(sfp->state, SFP_A2PAGE_UPDATE_INPROG);
277282
sfp->tolerance_count = IP_RESPONSE_TOLERANCE_LIMIT;
278283

279284
break;
280285

281286
case SFP_A2PAGE_UPDATE_INPROG:
282287
if (stat_off & A2_UPD_COMPLETE) {
283-
WRITE_ONCE(sfp->init, SFP_A2PAGE_UPDATE_COMPLETE);
288+
WRITE_ONCE(sfp->state, SFP_A2PAGE_UPDATE_COMPLETE);
284289
} else {
285290
if (--sfp->tolerance_count == IP_IRRESPONSIVE)
286-
WRITE_ONCE(sfp->init, SFP_INIT_RESET);
291+
WRITE_ONCE(sfp->state, SFP_INIT_RESET);
287292
}
288293
break;
289294

290295
case SFP_A0_UPDATE_ERROR:
291296
dev_err(sfp->dev, "SFP: A0 Page error observed, restarting A0 page operation\n");
292-
WRITE_ONCE(sfp->init, SFP_INIT_RESET);
297+
WRITE_ONCE(sfp->state, SFP_INIT_RESET);
293298
break;
294299

295300
case SFP_A2_UPDATE_ERROR:
296301
dev_err(sfp->dev, "SFP: A2 Page error observed, restarting A2 page operation\n");
297-
WRITE_ONCE(sfp->init, SFP_A0PAGE_UPDATE_COMPLETE);
302+
WRITE_ONCE(sfp->state, SFP_A0PAGE_UPDATE_COMPLETE);
298303
break;
299304

300305
case SFP_A2PAGE_UPDATE_COMPLETE:
@@ -348,7 +353,7 @@ static void sfp_page_copy(struct sfp *sfp)
348353
static int sfp_module_info(struct sfp *sfp, struct ethtool_modinfo *modinfo)
349354
{
350355
/* Atleast A0 page update is completed */
351-
if (!(sfp->init >= SFP_A0PAGE_UPDATE_COMPLETE))
356+
if (!(sfp->state >= SFP_A0PAGE_UPDATE_COMPLETE))
352357
return -EIO;
353358

354359
sfp_page_copy(sfp);
@@ -450,7 +455,7 @@ static const struct sfp_socket_ops sfp_module_ops = {
450455

451456
int sfp_init_work(struct sfp *sfp)
452457
{
453-
sfp->init = SFP_INIT_RESET;
458+
sfp->state = SFP_DETECT;
454459

455460
sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops);
456461
if (!sfp->sfp_bus)

include/linux/phy/sfp-mem.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
#define A2_EEPROM_SIZE (ETH_MODULE_SFF_8472_LEN/2) * IMPLEMENTED_A2PAGES
2828

2929
enum sfp_init_status {
30-
SFP_INIT_RESET = 0,
30+
SFP_DETECT = 0,
31+
SFP_INIT_RESET,
3132
SFP_INIT_DONE,
3233
SFP_A0PAGE_UPDATE_INPROG,
3334
SFP_A0PAGE_UPDATE_COMPLETE,
@@ -52,15 +53,15 @@ union sfp_a0_page {
5253
* @regmap: regmap for device.
5354
* @dwork: work struct for checking sfp plugin status.
5455
* @dev: point to device.
55-
* @init: sfp init status.
56+
* @state: sfp status.
5657
* @lock: lock for sfp initial function and status.
5758
*/
5859
struct sfp {
5960
void __iomem *base;
6061
struct regmap *regmap;
6162
struct delayed_work dwork;
6263
struct device *dev;
63-
enum sfp_init_status init;
64+
enum sfp_init_status state;
6465
struct mutex lock;
6566
u32 tolerance_count;
6667
struct sfp_bus *sfp_bus;

0 commit comments

Comments
 (0)