diff options
author | Olof Johansson <olof@lixom.net> | 2007-05-08 01:47:54 -0400 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2007-05-08 01:48:19 -0400 |
commit | bb6e9590792834f905a92e439a083254649c985c (patch) | |
tree | dd071254f52dbcef0373d1a9346276bd58be2adf /drivers/net/pasemi_mac.c | |
parent | ceb51361370c003e13f782edb7171a8383e5c849 (diff) |
pasemi_mac: PHY support
PHY support for pasemi_mac.
Signed-off-by: Olof Johansson <olof@lixom.net>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/net/pasemi_mac.c')
-rw-r--r-- | drivers/net/pasemi_mac.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/drivers/net/pasemi_mac.c b/drivers/net/pasemi_mac.c index 4c6d34d6989c..78b127c404e9 100644 --- a/drivers/net/pasemi_mac.c +++ b/drivers/net/pasemi_mac.c | |||
@@ -606,6 +606,114 @@ static irqreturn_t pasemi_mac_tx_intr(int irq, void *data) | |||
606 | return IRQ_HANDLED; | 606 | return IRQ_HANDLED; |
607 | } | 607 | } |
608 | 608 | ||
609 | static void pasemi_adjust_link(struct net_device *dev) | ||
610 | { | ||
611 | struct pasemi_mac *mac = netdev_priv(dev); | ||
612 | int msg; | ||
613 | unsigned int flags; | ||
614 | unsigned int new_flags; | ||
615 | |||
616 | if (!mac->phydev->link) { | ||
617 | /* If no link, MAC speed settings don't matter. Just report | ||
618 | * link down and return. | ||
619 | */ | ||
620 | if (mac->link && netif_msg_link(mac)) | ||
621 | printk(KERN_INFO "%s: Link is down.\n", dev->name); | ||
622 | |||
623 | netif_carrier_off(dev); | ||
624 | mac->link = 0; | ||
625 | |||
626 | return; | ||
627 | } else | ||
628 | netif_carrier_on(dev); | ||
629 | |||
630 | pci_read_config_dword(mac->pdev, PAS_MAC_CFG_PCFG, &flags); | ||
631 | new_flags = flags & ~(PAS_MAC_CFG_PCFG_HD | PAS_MAC_CFG_PCFG_SPD_M | | ||
632 | PAS_MAC_CFG_PCFG_TSR_M); | ||
633 | |||
634 | if (!mac->phydev->duplex) | ||
635 | new_flags |= PAS_MAC_CFG_PCFG_HD; | ||
636 | |||
637 | switch (mac->phydev->speed) { | ||
638 | case 1000: | ||
639 | new_flags |= PAS_MAC_CFG_PCFG_SPD_1G | | ||
640 | PAS_MAC_CFG_PCFG_TSR_1G; | ||
641 | break; | ||
642 | case 100: | ||
643 | new_flags |= PAS_MAC_CFG_PCFG_SPD_100M | | ||
644 | PAS_MAC_CFG_PCFG_TSR_100M; | ||
645 | break; | ||
646 | case 10: | ||
647 | new_flags |= PAS_MAC_CFG_PCFG_SPD_10M | | ||
648 | PAS_MAC_CFG_PCFG_TSR_10M; | ||
649 | break; | ||
650 | default: | ||
651 | printk("Unsupported speed %d\n", mac->phydev->speed); | ||
652 | } | ||
653 | |||
654 | /* Print on link or speed/duplex change */ | ||
655 | msg = mac->link != mac->phydev->link || flags != new_flags; | ||
656 | |||
657 | mac->duplex = mac->phydev->duplex; | ||
658 | mac->speed = mac->phydev->speed; | ||
659 | mac->link = mac->phydev->link; | ||
660 | |||
661 | if (new_flags != flags) | ||
662 | pci_write_config_dword(mac->pdev, PAS_MAC_CFG_PCFG, new_flags); | ||
663 | |||
664 | if (msg && netif_msg_link(mac)) | ||
665 | printk(KERN_INFO "%s: Link is up at %d Mbps, %s duplex.\n", | ||
666 | dev->name, mac->speed, mac->duplex ? "full" : "half"); | ||
667 | } | ||
668 | |||
669 | static int pasemi_mac_phy_init(struct net_device *dev) | ||
670 | { | ||
671 | struct pasemi_mac *mac = netdev_priv(dev); | ||
672 | struct device_node *dn, *phy_dn; | ||
673 | struct phy_device *phydev; | ||
674 | unsigned int phy_id; | ||
675 | const phandle *ph; | ||
676 | const unsigned int *prop; | ||
677 | struct resource r; | ||
678 | int ret; | ||
679 | |||
680 | dn = pci_device_to_OF_node(mac->pdev); | ||
681 | ph = get_property(dn, "phy-handle", NULL); | ||
682 | if (!ph) | ||
683 | return -ENODEV; | ||
684 | phy_dn = of_find_node_by_phandle(*ph); | ||
685 | |||
686 | prop = get_property(phy_dn, "reg", NULL); | ||
687 | ret = of_address_to_resource(phy_dn->parent, 0, &r); | ||
688 | if (ret) | ||
689 | goto err; | ||
690 | |||
691 | phy_id = *prop; | ||
692 | snprintf(mac->phy_id, BUS_ID_SIZE, PHY_ID_FMT, (int)r.start, phy_id); | ||
693 | |||
694 | of_node_put(phy_dn); | ||
695 | |||
696 | mac->link = 0; | ||
697 | mac->speed = 0; | ||
698 | mac->duplex = -1; | ||
699 | |||
700 | phydev = phy_connect(dev, mac->phy_id, &pasemi_adjust_link, 0, PHY_INTERFACE_MODE_SGMII); | ||
701 | |||
702 | if (IS_ERR(phydev)) { | ||
703 | printk(KERN_ERR "%s: Could not attach to phy\n", dev->name); | ||
704 | return PTR_ERR(phydev); | ||
705 | } | ||
706 | |||
707 | mac->phydev = phydev; | ||
708 | |||
709 | return 0; | ||
710 | |||
711 | err: | ||
712 | of_node_put(phy_dn); | ||
713 | return -ENODEV; | ||
714 | } | ||
715 | |||
716 | |||
609 | static int pasemi_mac_open(struct net_device *dev) | 717 | static int pasemi_mac_open(struct net_device *dev) |
610 | { | 718 | { |
611 | struct pasemi_mac *mac = netdev_priv(dev); | 719 | struct pasemi_mac *mac = netdev_priv(dev); |
@@ -678,6 +786,13 @@ static int pasemi_mac_open(struct net_device *dev) | |||
678 | 786 | ||
679 | pasemi_mac_replenish_rx_ring(dev); | 787 | pasemi_mac_replenish_rx_ring(dev); |
680 | 788 | ||
789 | ret = pasemi_mac_phy_init(dev); | ||
790 | /* Some configs don't have PHYs (XAUI etc), so don't complain about | ||
791 | * failed init due to -ENODEV. | ||
792 | */ | ||
793 | if (ret && ret != -ENODEV) | ||
794 | dev_warn(&mac->pdev->dev, "phy init failed: %d\n", ret); | ||
795 | |||
681 | netif_start_queue(dev); | 796 | netif_start_queue(dev); |
682 | netif_poll_enable(dev); | 797 | netif_poll_enable(dev); |
683 | 798 | ||
@@ -708,6 +823,9 @@ static int pasemi_mac_open(struct net_device *dev) | |||
708 | goto out_rx_int; | 823 | goto out_rx_int; |
709 | } | 824 | } |
710 | 825 | ||
826 | if (mac->phydev) | ||
827 | phy_start(mac->phydev); | ||
828 | |||
711 | return 0; | 829 | return 0; |
712 | 830 | ||
713 | out_rx_int: | 831 | out_rx_int: |
@@ -731,6 +849,11 @@ static int pasemi_mac_close(struct net_device *dev) | |||
731 | unsigned int stat; | 849 | unsigned int stat; |
732 | int retries; | 850 | int retries; |
733 | 851 | ||
852 | if (mac->phydev) { | ||
853 | phy_stop(mac->phydev); | ||
854 | phy_disconnect(mac->phydev); | ||
855 | } | ||
856 | |||
734 | netif_stop_queue(dev); | 857 | netif_stop_queue(dev); |
735 | 858 | ||
736 | /* Clean out any pending buffers */ | 859 | /* Clean out any pending buffers */ |
@@ -1028,6 +1151,9 @@ pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1028 | 1151 | ||
1029 | mac->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); | 1152 | mac->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
1030 | 1153 | ||
1154 | /* Enable most messages by default */ | ||
1155 | mac->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1; | ||
1156 | |||
1031 | err = register_netdev(dev); | 1157 | err = register_netdev(dev); |
1032 | 1158 | ||
1033 | if (err) { | 1159 | if (err) { |