Skip to content

Commit c481fed

Browse files
maass-hamburgdkalowsk
authored andcommitted
drivers: ethernet: phy: only use one worker
only use one worker for monitoring and autoneg. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
1 parent b0048e3 commit c481fed

File tree

1 file changed

+17
-57
lines changed

1 file changed

+17
-57
lines changed

drivers/ethernet/phy/phy_mii.c

Lines changed: 17 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ struct phy_mii_dev_data {
3838
struct k_sem sem;
3939
#if ANY_DYNAMIC_LINK
4040
struct k_work_delayable monitor_work;
41-
struct k_work_delayable autoneg_work;
4241
bool gigabit_supported;
4342
bool restart_autoneg;
43+
bool autoneg_in_progress;
4444
k_timepoint_t autoneg_timeout;
4545
#endif
4646
};
@@ -310,65 +310,27 @@ static void monitor_work_handler(struct k_work *work)
310310
const struct device *dev = data->dev;
311311
int rc;
312312

313-
if (k_sem_take(&data->sem, K_NO_WAIT) != 0) {
314-
/* Try again soon */
315-
k_work_reschedule(&data->monitor_work,
316-
K_MSEC(MII_AUTONEG_POLL_INTERVAL_MS));
317-
return;
318-
}
319-
320-
rc = update_link_state(dev);
321-
322-
k_sem_give(&data->sem);
323-
324-
/* If link state has changed and a callback is set, invoke callback */
325-
if (rc == 0) {
326-
invoke_link_cb(dev);
327-
}
328-
329-
if (rc == -EINPROGRESS) {
330-
/* Check for autonegotiation completion */
331-
k_work_reschedule(&data->autoneg_work,
332-
K_MSEC(MII_AUTONEG_POLL_INTERVAL_MS));
333-
} else {
334-
/* Submit delayed work */
335-
k_work_reschedule(&data->monitor_work, K_MSEC(CONFIG_PHY_MONITOR_PERIOD));
336-
}
337-
}
338-
339-
static void autoneg_work_handler(struct k_work *work)
340-
{
341-
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
342-
struct phy_mii_dev_data *const data =
343-
CONTAINER_OF(dwork, struct phy_mii_dev_data, autoneg_work);
344-
const struct device *dev = data->dev;
345-
int rc;
346-
347-
if (k_sem_take(&data->sem, K_NO_WAIT) != 0) {
348-
/* Try again soon */
349-
k_work_reschedule(&data->autoneg_work,
350-
K_MSEC(MII_AUTONEG_POLL_INTERVAL_MS));
351-
return;
352-
}
313+
if (k_sem_take(&data->sem, K_NO_WAIT) == 0) {
314+
if (data->autoneg_in_progress) {
315+
rc = check_autonegotiation_completion(dev);
316+
} else {
317+
/* If autonegotiation is not in progress, just update the link state */
318+
rc = update_link_state(dev);
319+
}
353320

354-
rc = check_autonegotiation_completion(dev);
321+
data->autoneg_in_progress = (rc == -EINPROGRESS);
355322

356-
k_sem_give(&data->sem);
323+
k_sem_give(&data->sem);
357324

358-
/* If link state has changed and a callback is set, invoke callback */
359-
if (rc == 0) {
360-
invoke_link_cb(dev);
325+
/* If link state has changed and a callback is set, invoke callback */
326+
if (rc == 0) {
327+
invoke_link_cb(dev);
328+
}
361329
}
362330

363-
if (rc == -EINPROGRESS) {
364-
/* Check again soon */
365-
k_work_reschedule(&data->autoneg_work,
366-
K_MSEC(MII_AUTONEG_POLL_INTERVAL_MS));
367-
} else {
368-
/* Schedule the next monitoring call */
369-
k_work_reschedule(&data->monitor_work,
370-
K_MSEC(CONFIG_PHY_MONITOR_PERIOD));
371-
}
331+
k_work_reschedule(&data->monitor_work, data->autoneg_in_progress
332+
? K_MSEC(MII_AUTONEG_POLL_INTERVAL_MS)
333+
: K_MSEC(CONFIG_PHY_MONITOR_PERIOD));
372334
}
373335

374336
static int phy_mii_read(const struct device *dev, uint16_t reg_addr,
@@ -490,7 +452,6 @@ static int phy_mii_cfg_link(const struct device *dev,
490452
}
491453

492454
if (data->restart_autoneg && data->state.is_up) {
493-
k_work_cancel_delayable(&data->autoneg_work);
494455
k_work_reschedule(&data->monitor_work, K_NO_WAIT);
495456
}
496457

@@ -609,7 +570,6 @@ static int phy_mii_initialize_dynamic_link(const struct device *dev)
609570
data->gigabit_supported = is_gigabit_supported(dev);
610571

611572
k_work_init_delayable(&data->monitor_work, monitor_work_handler);
612-
k_work_init_delayable(&data->autoneg_work, autoneg_work_handler);
613573

614574
/* Advertise default speeds */
615575
phy_mii_cfg_link(dev, cfg->default_speeds);

0 commit comments

Comments
 (0)