diff options
Diffstat (limited to 'drivers/net/phy/phy.c')
-rw-r--r-- | drivers/net/phy/phy.c | 113 |
1 files changed, 65 insertions, 48 deletions
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 3af9fcf76c81..88237bdb5255 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * Author: Andy Fleming | 7 | * Author: Andy Fleming |
8 | * | 8 | * |
9 | * Copyright (c) 2004 Freescale Semiconductor, Inc. | 9 | * Copyright (c) 2004 Freescale Semiconductor, Inc. |
10 | * Copyright (c) 2006 Maciej W. Rozycki | ||
10 | * | 11 | * |
11 | * This program is free software; you can redistribute it and/or modify it | 12 | * This program is free software; you can redistribute it and/or modify it |
12 | * under the terms of the GNU General Public License as published by the | 13 | * under the terms of the GNU General Public License as published by the |
@@ -32,6 +33,8 @@ | |||
32 | #include <linux/mii.h> | 33 | #include <linux/mii.h> |
33 | #include <linux/ethtool.h> | 34 | #include <linux/ethtool.h> |
34 | #include <linux/phy.h> | 35 | #include <linux/phy.h> |
36 | #include <linux/timer.h> | ||
37 | #include <linux/workqueue.h> | ||
35 | 38 | ||
36 | #include <asm/io.h> | 39 | #include <asm/io.h> |
37 | #include <asm/irq.h> | 40 | #include <asm/irq.h> |
@@ -484,6 +487,9 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat) | |||
484 | { | 487 | { |
485 | struct phy_device *phydev = phy_dat; | 488 | struct phy_device *phydev = phy_dat; |
486 | 489 | ||
490 | if (PHY_HALTED == phydev->state) | ||
491 | return IRQ_NONE; /* It can't be ours. */ | ||
492 | |||
487 | /* The MDIO bus is not allowed to be written in interrupt | 493 | /* The MDIO bus is not allowed to be written in interrupt |
488 | * context, so we need to disable the irq here. A work | 494 | * context, so we need to disable the irq here. A work |
489 | * queue will write the PHY to disable and clear the | 495 | * queue will write the PHY to disable and clear the |
@@ -577,6 +583,13 @@ int phy_stop_interrupts(struct phy_device *phydev) | |||
577 | if (err) | 583 | if (err) |
578 | phy_error(phydev); | 584 | phy_error(phydev); |
579 | 585 | ||
586 | /* | ||
587 | * Finish any pending work; we might have been scheduled | ||
588 | * to be called from keventd ourselves, though. | ||
589 | */ | ||
590 | if (!current_is_keventd()) | ||
591 | flush_scheduled_work(); | ||
592 | |||
580 | free_irq(phydev->irq, phydev); | 593 | free_irq(phydev->irq, phydev); |
581 | 594 | ||
582 | return err; | 595 | return err; |
@@ -603,7 +616,8 @@ static void phy_change(void *data) | |||
603 | enable_irq(phydev->irq); | 616 | enable_irq(phydev->irq); |
604 | 617 | ||
605 | /* Reenable interrupts */ | 618 | /* Reenable interrupts */ |
606 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); | 619 | if (PHY_HALTED != phydev->state) |
620 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); | ||
607 | 621 | ||
608 | if (err) | 622 | if (err) |
609 | goto irq_enable_err; | 623 | goto irq_enable_err; |
@@ -624,18 +638,24 @@ void phy_stop(struct phy_device *phydev) | |||
624 | if (PHY_HALTED == phydev->state) | 638 | if (PHY_HALTED == phydev->state) |
625 | goto out_unlock; | 639 | goto out_unlock; |
626 | 640 | ||
627 | if (phydev->irq != PHY_POLL) { | 641 | phydev->state = PHY_HALTED; |
628 | /* Clear any pending interrupts */ | ||
629 | phy_clear_interrupt(phydev); | ||
630 | 642 | ||
643 | if (phydev->irq != PHY_POLL) { | ||
631 | /* Disable PHY Interrupts */ | 644 | /* Disable PHY Interrupts */ |
632 | phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); | 645 | phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); |
633 | } | ||
634 | 646 | ||
635 | phydev->state = PHY_HALTED; | 647 | /* Clear any pending interrupts */ |
648 | phy_clear_interrupt(phydev); | ||
649 | } | ||
636 | 650 | ||
637 | out_unlock: | 651 | out_unlock: |
638 | spin_unlock(&phydev->lock); | 652 | spin_unlock(&phydev->lock); |
653 | |||
654 | /* | ||
655 | * Cannot call flush_scheduled_work() here as desired because | ||
656 | * of rtnl_lock(), but PHY_HALTED shall guarantee phy_change() | ||
657 | * will not reenable interrupts. | ||
658 | */ | ||
639 | } | 659 | } |
640 | 660 | ||
641 | 661 | ||
@@ -693,60 +713,57 @@ static void phy_timer(unsigned long data) | |||
693 | 713 | ||
694 | break; | 714 | break; |
695 | case PHY_AN: | 715 | case PHY_AN: |
716 | err = phy_read_status(phydev); | ||
717 | |||
718 | if (err < 0) | ||
719 | break; | ||
720 | |||
721 | /* If the link is down, give up on | ||
722 | * negotiation for now */ | ||
723 | if (!phydev->link) { | ||
724 | phydev->state = PHY_NOLINK; | ||
725 | netif_carrier_off(phydev->attached_dev); | ||
726 | phydev->adjust_link(phydev->attached_dev); | ||
727 | break; | ||
728 | } | ||
729 | |||
696 | /* Check if negotiation is done. Break | 730 | /* Check if negotiation is done. Break |
697 | * if there's an error */ | 731 | * if there's an error */ |
698 | err = phy_aneg_done(phydev); | 732 | err = phy_aneg_done(phydev); |
699 | if (err < 0) | 733 | if (err < 0) |
700 | break; | 734 | break; |
701 | 735 | ||
702 | /* If auto-negotiation is done, we change to | 736 | /* If AN is done, we're running */ |
703 | * either RUNNING, or NOLINK */ | ||
704 | if (err > 0) { | 737 | if (err > 0) { |
705 | err = phy_read_status(phydev); | 738 | phydev->state = PHY_RUNNING; |
739 | netif_carrier_on(phydev->attached_dev); | ||
740 | phydev->adjust_link(phydev->attached_dev); | ||
741 | |||
742 | } else if (0 == phydev->link_timeout--) { | ||
743 | int idx; | ||
706 | 744 | ||
707 | if (err) | 745 | needs_aneg = 1; |
746 | /* If we have the magic_aneg bit, | ||
747 | * we try again */ | ||
748 | if (phydev->drv->flags & PHY_HAS_MAGICANEG) | ||
708 | break; | 749 | break; |
709 | 750 | ||
710 | if (phydev->link) { | 751 | /* The timer expired, and we still |
711 | phydev->state = PHY_RUNNING; | 752 | * don't have a setting, so we try |
712 | netif_carrier_on(phydev->attached_dev); | 753 | * forcing it until we find one that |
713 | } else { | 754 | * works, starting from the fastest speed, |
714 | phydev->state = PHY_NOLINK; | 755 | * and working our way down */ |
715 | netif_carrier_off(phydev->attached_dev); | 756 | idx = phy_find_valid(0, phydev->supported); |
716 | } | ||
717 | 757 | ||
718 | phydev->adjust_link(phydev->attached_dev); | 758 | phydev->speed = settings[idx].speed; |
759 | phydev->duplex = settings[idx].duplex; | ||
719 | 760 | ||
720 | } else if (0 == phydev->link_timeout--) { | 761 | phydev->autoneg = AUTONEG_DISABLE; |
721 | /* The counter expired, so either we | ||
722 | * switch to forced mode, or the | ||
723 | * magic_aneg bit exists, and we try aneg | ||
724 | * again */ | ||
725 | if (!(phydev->drv->flags & PHY_HAS_MAGICANEG)) { | ||
726 | int idx; | ||
727 | |||
728 | /* We'll start from the | ||
729 | * fastest speed, and work | ||
730 | * our way down */ | ||
731 | idx = phy_find_valid(0, | ||
732 | phydev->supported); | ||
733 | |||
734 | phydev->speed = settings[idx].speed; | ||
735 | phydev->duplex = settings[idx].duplex; | ||
736 | |||
737 | phydev->autoneg = AUTONEG_DISABLE; | ||
738 | phydev->state = PHY_FORCING; | ||
739 | phydev->link_timeout = | ||
740 | PHY_FORCE_TIMEOUT; | ||
741 | |||
742 | pr_info("Trying %d/%s\n", | ||
743 | phydev->speed, | ||
744 | DUPLEX_FULL == | ||
745 | phydev->duplex ? | ||
746 | "FULL" : "HALF"); | ||
747 | } | ||
748 | 762 | ||
749 | needs_aneg = 1; | 763 | pr_info("Trying %d/%s\n", phydev->speed, |
764 | DUPLEX_FULL == | ||
765 | phydev->duplex ? | ||
766 | "FULL" : "HALF"); | ||
750 | } | 767 | } |
751 | break; | 768 | break; |
752 | case PHY_NOLINK: | 769 | case PHY_NOLINK: |
@@ -762,7 +779,7 @@ static void phy_timer(unsigned long data) | |||
762 | } | 779 | } |
763 | break; | 780 | break; |
764 | case PHY_FORCING: | 781 | case PHY_FORCING: |
765 | err = phy_read_status(phydev); | 782 | err = genphy_update_link(phydev); |
766 | 783 | ||
767 | if (err) | 784 | if (err) |
768 | break; | 785 | break; |