aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/phy/phy.c
diff options
context:
space:
mode:
authorSergei Shtylyov <sergei.shtylyov@cogentembedded.com>2014-01-04 19:17:06 -0500
committerDavid S. Miller <davem@davemloft.net>2014-01-04 19:27:57 -0500
commit2f53e9047e79b638b155785f03dae8999da93bad (patch)
tree3dfad42aaed7f7b0556bc5d14eb491e88b7bd456 /drivers/net/phy/phy.c
parentffeed1beb62f3742693598dfe2f1c010de249bba (diff)
phy: coding style fixes
The recent patch from Florian Fainelli fixed all 'checkpatch.pl' errors but left the numerous warnings: - including <asm/io.h> instead of <linux/io.h>; - including <asm/uaccess.h> instead of <linux/uaccess.h>; - *extern* declaration in .c file; - block comments using empty /* line; - block comments not starting with * on the middle lines; - block comments not having trailing */ on a separate line; - EXPORT_SYMBOL() not immediately following its function; - unnecessary {} for signle statement block; - spaces before tabs. While fixing these, also fix the following style issues (some of which were found running 'checkpatch.pl --strict'): - alignment not matching open paren; - missing {} on one of the *if* arms where another has them; - use of sizeof(struct structure) instead of sizeof(*variable); - multiple assignments on one line; - empty line before }; - file names in the heading comments; - missing spaces around operators; - no {} around multi-line *if* operator's arm; - unneeded () around subexpressions; - incomplete kernel-doc comment style; - comment line exceeding 80 characters; - missing empty line after declarations. Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/phy/phy.c')
-rw-r--r--drivers/net/phy/phy.c82
1 files changed, 36 insertions, 46 deletions
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 20908865709f..056706aa9fbc 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1,7 +1,4 @@
1/* 1/* Framework for configuring and reading PHY devices
2 * drivers/net/phy/phy.c
3 *
4 * Framework for configuring and reading PHY devices
5 * Based on code in sungem_phy.c and gianfar_phy.c 2 * Based on code in sungem_phy.c and gianfar_phy.c
6 * 3 *
7 * Author: Andy Fleming 4 * Author: Andy Fleming
@@ -36,11 +33,11 @@
36#include <linux/timer.h> 33#include <linux/timer.h>
37#include <linux/workqueue.h> 34#include <linux/workqueue.h>
38#include <linux/mdio.h> 35#include <linux/mdio.h>
39 36#include <linux/io.h>
37#include <linux/uaccess.h>
40#include <linux/atomic.h> 38#include <linux/atomic.h>
41#include <asm/io.h> 39
42#include <asm/irq.h> 40#include <asm/irq.h>
43#include <asm/uaccess.h>
44 41
45/** 42/**
46 * phy_print_status - Convenience function to print out the current phy status 43 * phy_print_status - Convenience function to print out the current phy status
@@ -48,13 +45,14 @@
48 */ 45 */
49void phy_print_status(struct phy_device *phydev) 46void phy_print_status(struct phy_device *phydev)
50{ 47{
51 if (phydev->link) 48 if (phydev->link) {
52 pr_info("%s - Link is Up - %d/%s\n", 49 pr_info("%s - Link is Up - %d/%s\n",
53 dev_name(&phydev->dev), 50 dev_name(&phydev->dev),
54 phydev->speed, 51 phydev->speed,
55 DUPLEX_FULL == phydev->duplex ? "Full" : "Half"); 52 DUPLEX_FULL == phydev->duplex ? "Full" : "Half");
56 else 53 } else {
57 pr_info("%s - Link is Down\n", dev_name(&phydev->dev)); 54 pr_info("%s - Link is Down\n", dev_name(&phydev->dev));
55 }
58} 56}
59EXPORT_SYMBOL(phy_print_status); 57EXPORT_SYMBOL(phy_print_status);
60 58
@@ -114,7 +112,8 @@ static inline int phy_aneg_done(struct phy_device *phydev)
114} 112}
115 113
116/* A structure for mapping a particular speed and duplex 114/* A structure for mapping a particular speed and duplex
117 * combination to a particular SUPPORTED and ADVERTISED value */ 115 * combination to a particular SUPPORTED and ADVERTISED value
116 */
118struct phy_setting { 117struct phy_setting {
119 int speed; 118 int speed;
120 int duplex; 119 int duplex;
@@ -177,8 +176,7 @@ static inline int phy_find_setting(int speed, int duplex)
177 int idx = 0; 176 int idx = 0;
178 177
179 while (idx < ARRAY_SIZE(settings) && 178 while (idx < ARRAY_SIZE(settings) &&
180 (settings[idx].speed != speed || 179 (settings[idx].speed != speed || settings[idx].duplex != duplex))
181 settings[idx].duplex != duplex))
182 idx++; 180 idx++;
183 181
184 return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1; 182 return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1;
@@ -245,8 +243,7 @@ int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd)
245 if (cmd->phy_address != phydev->addr) 243 if (cmd->phy_address != phydev->addr)
246 return -EINVAL; 244 return -EINVAL;
247 245
248 /* We make sure that we don't pass unsupported 246 /* We make sure that we don't pass unsupported values in to the PHY */
249 * values in to the PHY */
250 cmd->advertising &= phydev->supported; 247 cmd->advertising &= phydev->supported;
251 248
252 /* Verify the settings we care about. */ 249 /* Verify the settings we care about. */
@@ -313,8 +310,7 @@ EXPORT_SYMBOL(phy_ethtool_gset);
313 * PHYCONTROL layer. It changes registers without regard to 310 * PHYCONTROL layer. It changes registers without regard to
314 * current state. Use at own risk. 311 * current state. Use at own risk.
315 */ 312 */
316int phy_mii_ioctl(struct phy_device *phydev, 313int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
317 struct ifreq *ifr, int cmd)
318{ 314{
319 struct mii_ioctl_data *mii_data = if_mii(ifr); 315 struct mii_ioctl_data *mii_data = if_mii(ifr);
320 u16 val = mii_data->val_in; 316 u16 val = mii_data->val_in;
@@ -334,19 +330,18 @@ int phy_mii_ioctl(struct phy_device *phydev,
334 if (mii_data->phy_id == phydev->addr) { 330 if (mii_data->phy_id == phydev->addr) {
335 switch (mii_data->reg_num) { 331 switch (mii_data->reg_num) {
336 case MII_BMCR: 332 case MII_BMCR:
337 if ((val & (BMCR_RESET|BMCR_ANENABLE)) == 0) 333 if ((val & (BMCR_RESET | BMCR_ANENABLE)) == 0)
338 phydev->autoneg = AUTONEG_DISABLE; 334 phydev->autoneg = AUTONEG_DISABLE;
339 else 335 else
340 phydev->autoneg = AUTONEG_ENABLE; 336 phydev->autoneg = AUTONEG_ENABLE;
341 if ((!phydev->autoneg) && (val & BMCR_FULLDPLX)) 337 if (!phydev->autoneg && (val & BMCR_FULLDPLX))
342 phydev->duplex = DUPLEX_FULL; 338 phydev->duplex = DUPLEX_FULL;
343 else 339 else
344 phydev->duplex = DUPLEX_HALF; 340 phydev->duplex = DUPLEX_HALF;
345 if ((!phydev->autoneg) && 341 if (!phydev->autoneg && (val & BMCR_SPEED1000))
346 (val & BMCR_SPEED1000))
347 phydev->speed = SPEED_1000; 342 phydev->speed = SPEED_1000;
348 else if ((!phydev->autoneg) && 343 else if (!phydev->autoneg &&
349 (val & BMCR_SPEED100)) 344 (val & BMCR_SPEED100))
350 phydev->speed = SPEED_100; 345 phydev->speed = SPEED_100;
351 break; 346 break;
352 case MII_ADVERTISE: 347 case MII_ADVERTISE:
@@ -433,7 +428,7 @@ EXPORT_SYMBOL(phy_start_aneg);
433 * function. 428 * function.
434 */ 429 */
435void phy_start_machine(struct phy_device *phydev, 430void phy_start_machine(struct phy_device *phydev,
436 void (*handler)(struct net_device *)) 431 void (*handler)(struct net_device *))
437{ 432{
438 phydev->adjust_state = handler; 433 phydev->adjust_state = handler;
439 434
@@ -494,7 +489,8 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
494 /* The MDIO bus is not allowed to be written in interrupt 489 /* The MDIO bus is not allowed to be written in interrupt
495 * context, so we need to disable the irq here. A work 490 * context, so we need to disable the irq here. A work
496 * queue will write the PHY to disable and clear the 491 * queue will write the PHY to disable and clear the
497 * interrupt, and then reenable the irq line. */ 492 * interrupt, and then reenable the irq line.
493 */
498 disable_irq_nosync(irq); 494 disable_irq_nosync(irq);
499 atomic_inc(&phydev->irq_disable); 495 atomic_inc(&phydev->irq_disable);
500 496
@@ -595,15 +591,13 @@ int phy_stop_interrupts(struct phy_device *phydev)
595 591
596 free_irq(phydev->irq, phydev); 592 free_irq(phydev->irq, phydev);
597 593
598 /* 594 /* Cannot call flush_scheduled_work() here as desired because
599 * Cannot call flush_scheduled_work() here as desired because
600 * of rtnl_lock(), but we do not really care about what would 595 * of rtnl_lock(), but we do not really care about what would
601 * be done, except from enable_irq(), so cancel any work 596 * be done, except from enable_irq(), so cancel any work
602 * possibly pending and take care of the matter below. 597 * possibly pending and take care of the matter below.
603 */ 598 */
604 cancel_work_sync(&phydev->phy_queue); 599 cancel_work_sync(&phydev->phy_queue);
605 /* 600 /* If work indeed has been cancelled, disable_irq() will have
606 * If work indeed has been cancelled, disable_irq() will have
607 * been left unbalanced from phy_interrupt() and enable_irq() 601 * been left unbalanced from phy_interrupt() and enable_irq()
608 * has to be called so that other devices on the line work. 602 * has to be called so that other devices on the line work.
609 */ 603 */
@@ -691,12 +685,12 @@ void phy_stop(struct phy_device *phydev)
691out_unlock: 685out_unlock:
692 mutex_unlock(&phydev->lock); 686 mutex_unlock(&phydev->lock);
693 687
694 /* 688 /* Cannot call flush_scheduled_work() here as desired because
695 * Cannot call flush_scheduled_work() here as desired because
696 * of rtnl_lock(), but PHY_HALTED shall guarantee phy_change() 689 * of rtnl_lock(), but PHY_HALTED shall guarantee phy_change()
697 * will not reenable interrupts. 690 * will not reenable interrupts.
698 */ 691 */
699} 692}
693EXPORT_SYMBOL(phy_stop);
700 694
701 695
702/** 696/**
@@ -727,7 +721,6 @@ void phy_start(struct phy_device *phydev)
727 } 721 }
728 mutex_unlock(&phydev->lock); 722 mutex_unlock(&phydev->lock);
729} 723}
730EXPORT_SYMBOL(phy_stop);
731EXPORT_SYMBOL(phy_start); 724EXPORT_SYMBOL(phy_start);
732 725
733/** 726/**
@@ -765,8 +758,7 @@ void phy_state_machine(struct work_struct *work)
765 if (err < 0) 758 if (err < 0)
766 break; 759 break;
767 760
768 /* If the link is down, give up on 761 /* If the link is down, give up on negotiation for now */
769 * negotiation for now */
770 if (!phydev->link) { 762 if (!phydev->link) {
771 phydev->state = PHY_NOLINK; 763 phydev->state = PHY_NOLINK;
772 netif_carrier_off(phydev->attached_dev); 764 netif_carrier_off(phydev->attached_dev);
@@ -774,8 +766,7 @@ void phy_state_machine(struct work_struct *work)
774 break; 766 break;
775 } 767 }
776 768
777 /* Check if negotiation is done. Break 769 /* Check if negotiation is done. Break if there's an error */
778 * if there's an error */
779 err = phy_aneg_done(phydev); 770 err = phy_aneg_done(phydev);
780 if (err < 0) 771 if (err < 0)
781 break; 772 break;
@@ -788,8 +779,7 @@ void phy_state_machine(struct work_struct *work)
788 779
789 } else if (0 == phydev->link_timeout--) { 780 } else if (0 == phydev->link_timeout--) {
790 needs_aneg = 1; 781 needs_aneg = 1;
791 /* If we have the magic_aneg bit, 782 /* If we have the magic_aneg bit, we try again */
792 * we try again */
793 if (phydev->drv->flags & PHY_HAS_MAGICANEG) 783 if (phydev->drv->flags & PHY_HAS_MAGICANEG)
794 break; 784 break;
795 } 785 }
@@ -847,7 +837,7 @@ void phy_state_machine(struct work_struct *work)
847 837
848 if (phy_interrupt_is_valid(phydev)) 838 if (phy_interrupt_is_valid(phydev))
849 err = phy_config_interrupt(phydev, 839 err = phy_config_interrupt(phydev,
850 PHY_INTERRUPT_ENABLED); 840 PHY_INTERRUPT_ENABLED);
851 break; 841 break;
852 case PHY_HALTED: 842 case PHY_HALTED:
853 if (phydev->link) { 843 if (phydev->link) {
@@ -864,8 +854,7 @@ void phy_state_machine(struct work_struct *work)
864 if (err) 854 if (err)
865 break; 855 break;
866 856
867 err = phy_config_interrupt(phydev, 857 err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED);
868 PHY_INTERRUPT_ENABLED);
869 858
870 if (err) 859 if (err)
871 break; 860 break;
@@ -876,8 +865,8 @@ void phy_state_machine(struct work_struct *work)
876 break; 865 break;
877 866
878 /* err > 0 if AN is done. 867 /* err > 0 if AN is done.
879 * Otherwise, it's 0, and we're 868 * Otherwise, it's 0, and we're still waiting for AN
880 * still waiting for AN */ 869 */
881 if (err > 0) { 870 if (err > 0) {
882 err = phy_read_status(phydev); 871 err = phy_read_status(phydev);
883 if (err) 872 if (err)
@@ -886,8 +875,9 @@ void phy_state_machine(struct work_struct *work)
886 if (phydev->link) { 875 if (phydev->link) {
887 phydev->state = PHY_RUNNING; 876 phydev->state = PHY_RUNNING;
888 netif_carrier_on(phydev->attached_dev); 877 netif_carrier_on(phydev->attached_dev);
889 } else 878 } else {
890 phydev->state = PHY_NOLINK; 879 phydev->state = PHY_NOLINK;
880 }
891 phydev->adjust_link(phydev->attached_dev); 881 phydev->adjust_link(phydev->attached_dev);
892 } else { 882 } else {
893 phydev->state = PHY_AN; 883 phydev->state = PHY_AN;
@@ -901,8 +891,9 @@ void phy_state_machine(struct work_struct *work)
901 if (phydev->link) { 891 if (phydev->link) {
902 phydev->state = PHY_RUNNING; 892 phydev->state = PHY_RUNNING;
903 netif_carrier_on(phydev->attached_dev); 893 netif_carrier_on(phydev->attached_dev);
904 } else 894 } else {
905 phydev->state = PHY_NOLINK; 895 phydev->state = PHY_NOLINK;
896 }
906 phydev->adjust_link(phydev->attached_dev); 897 phydev->adjust_link(phydev->attached_dev);
907 } 898 }
908 break; 899 break;
@@ -920,7 +911,7 @@ void phy_state_machine(struct work_struct *work)
920 phy_error(phydev); 911 phy_error(phydev);
921 912
922 queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, 913 queue_delayed_work(system_power_efficient_wq, &phydev->state_queue,
923 PHY_STATE_TIME * HZ); 914 PHY_STATE_TIME * HZ);
924} 915}
925 916
926void phy_mac_interrupt(struct phy_device *phydev, int new_link) 917void phy_mac_interrupt(struct phy_device *phydev, int new_link)
@@ -1091,7 +1082,6 @@ int phy_get_eee_err(struct phy_device *phydev)
1091{ 1082{
1092 return phy_read_mmd_indirect(phydev->bus, MDIO_PCS_EEE_WK_ERR, 1083 return phy_read_mmd_indirect(phydev->bus, MDIO_PCS_EEE_WK_ERR,
1093 MDIO_MMD_PCS, phydev->addr); 1084 MDIO_MMD_PCS, phydev->addr);
1094
1095} 1085}
1096EXPORT_SYMBOL(phy_get_eee_err); 1086EXPORT_SYMBOL(phy_get_eee_err);
1097 1087