Skip to content

Commit fa28a2b

Browse files
committed
Merge branch 'phylib-simplifications'
Heiner Kallweit says: ==================== net: phy: further phylib simplifications after recent changes to the state machine After the recent changes to the state machine phylib can be further simplified (w/o having to make any assumptions). ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents d79e26a + 34d884e commit fa28a2b

File tree

3 files changed

+17
-61
lines changed

3 files changed

+17
-61
lines changed

drivers/net/phy/phy.c

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -723,30 +723,26 @@ static int phy_disable_interrupts(struct phy_device *phydev)
723723
}
724724

725725
/**
726-
* phy_change - Called by the phy_interrupt to handle PHY changes
727-
* @phydev: phy_device struct that interrupted
726+
* phy_interrupt - PHY interrupt handler
727+
* @irq: interrupt line
728+
* @phy_dat: phy_device pointer
729+
*
730+
* Description: Handle PHY interrupt
728731
*/
729-
static irqreturn_t phy_change(struct phy_device *phydev)
732+
static irqreturn_t phy_interrupt(int irq, void *phy_dat)
730733
{
731-
if (phy_interrupt_is_valid(phydev)) {
732-
if (phydev->drv->did_interrupt &&
733-
!phydev->drv->did_interrupt(phydev))
734-
return IRQ_NONE;
735-
736-
if (phydev->state == PHY_HALTED)
737-
if (phy_disable_interrupts(phydev))
738-
goto phy_err;
739-
}
734+
struct phy_device *phydev = phy_dat;
740735

741-
mutex_lock(&phydev->lock);
742-
if ((PHY_RUNNING == phydev->state) || (PHY_NOLINK == phydev->state))
743-
phydev->state = PHY_CHANGELINK;
744-
mutex_unlock(&phydev->lock);
736+
if (PHY_HALTED == phydev->state)
737+
return IRQ_NONE; /* It can't be ours. */
738+
739+
if (phydev->drv->did_interrupt && !phydev->drv->did_interrupt(phydev))
740+
return IRQ_NONE;
745741

746742
/* reschedule state queue work to run as soon as possible */
747743
phy_trigger_machine(phydev);
748744

749-
if (phy_interrupt_is_valid(phydev) && phy_clear_interrupt(phydev))
745+
if (phy_clear_interrupt(phydev))
750746
goto phy_err;
751747
return IRQ_HANDLED;
752748

@@ -755,36 +751,6 @@ static irqreturn_t phy_change(struct phy_device *phydev)
755751
return IRQ_NONE;
756752
}
757753

758-
/**
759-
* phy_change_work - Scheduled by the phy_mac_interrupt to handle PHY changes
760-
* @work: work_struct that describes the work to be done
761-
*/
762-
void phy_change_work(struct work_struct *work)
763-
{
764-
struct phy_device *phydev =
765-
container_of(work, struct phy_device, phy_queue);
766-
767-
phy_change(phydev);
768-
}
769-
770-
/**
771-
* phy_interrupt - PHY interrupt handler
772-
* @irq: interrupt line
773-
* @phy_dat: phy_device pointer
774-
*
775-
* Description: When a PHY interrupt occurs, the handler disables
776-
* interrupts, and uses phy_change to handle the interrupt.
777-
*/
778-
static irqreturn_t phy_interrupt(int irq, void *phy_dat)
779-
{
780-
struct phy_device *phydev = phy_dat;
781-
782-
if (PHY_HALTED == phydev->state)
783-
return IRQ_NONE; /* It can't be ours. */
784-
785-
return phy_change(phydev);
786-
}
787-
788754
/**
789755
* phy_enable_interrupts - Enable the interrupts from the PHY side
790756
* @phydev: target phy_device struct
@@ -863,7 +829,7 @@ void phy_stop(struct phy_device *phydev)
863829
phy_state_machine(&phydev->state_queue.work);
864830

865831
/* Cannot call flush_scheduled_work() here as desired because
866-
* of rtnl_lock(), but PHY_HALTED shall guarantee phy_change()
832+
* of rtnl_lock(), but PHY_HALTED shall guarantee irq handler
867833
* will not reenable interrupts.
868834
*/
869835
}
@@ -946,9 +912,6 @@ void phy_state_machine(struct work_struct *work)
946912
break;
947913
case PHY_NOLINK:
948914
case PHY_RUNNING:
949-
if (!phy_polling_mode(phydev))
950-
break;
951-
/* fall through */
952915
case PHY_CHANGELINK:
953916
case PHY_RESUMING:
954917
err = phy_check_link_status(phydev);
@@ -1013,7 +976,7 @@ void phy_state_machine(struct work_struct *work)
1013976
void phy_mac_interrupt(struct phy_device *phydev)
1014977
{
1015978
/* Trigger a state machine change */
1016-
queue_work(system_power_efficient_wq, &phydev->phy_queue);
979+
phy_trigger_machine(phydev);
1017980
}
1018981
EXPORT_SYMBOL(phy_mac_interrupt);
1019982

drivers/net/phy/phy_device.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
587587

588588
mutex_init(&dev->lock);
589589
INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine);
590-
INIT_WORK(&dev->phy_queue, phy_change_work);
591590

592591
/* Request the appropriate module unconditionally; don't
593592
* bother trying to do so only if it isn't already loaded,

include/linux/phy.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
298298
* - timer moves to NOLINK or RUNNING
299299
*
300300
* NOLINK: PHY is up, but not currently plugged in.
301-
* - If the timer notes that the link comes back, we move to RUNNING
301+
* - irq or timer will set RUNNING if link comes back
302302
* - phy_stop moves to HALTED
303303
*
304304
* FORCING: PHY is being configured with forced settings
@@ -309,10 +309,7 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
309309
*
310310
* RUNNING: PHY is currently up, running, and possibly sending
311311
* and/or receiving packets
312-
* - timer will set CHANGELINK if we're polling (this ensures the
313-
* link state is polled every other cycle of this state machine,
314-
* which makes it every other second)
315-
* - irq will set CHANGELINK
312+
* - irq or timer will set NOLINK if link goes down
316313
* - phy_stop moves to HALTED
317314
*
318315
* CHANGELINK: PHY experienced a change in link state
@@ -372,7 +369,6 @@ struct phy_c45_device_ids {
372369
* giving up on the current attempt at acquiring a link
373370
* irq: IRQ number of the PHY's interrupt (-1 if none)
374371
* phy_timer: The timer for handling the state machine
375-
* phy_queue: A work_queue for the phy_mac_interrupt
376372
* attached_dev: The attached enet driver's device instance ptr
377373
* adjust_link: Callback for the enet controller to respond to
378374
* changes in the link state.
@@ -457,7 +453,6 @@ struct phy_device {
457453
void *priv;
458454

459455
/* Interrupt and Polling infrastructure */
460-
struct work_struct phy_queue;
461456
struct delayed_work state_queue;
462457

463458
struct mutex lock;
@@ -1032,7 +1027,6 @@ int phy_driver_register(struct phy_driver *new_driver, struct module *owner);
10321027
int phy_drivers_register(struct phy_driver *new_driver, int n,
10331028
struct module *owner);
10341029
void phy_state_machine(struct work_struct *work);
1035-
void phy_change_work(struct work_struct *work);
10361030
void phy_mac_interrupt(struct phy_device *phydev);
10371031
void phy_start_machine(struct phy_device *phydev);
10381032
void phy_stop_machine(struct phy_device *phydev);

0 commit comments

Comments
 (0)