aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/phy/phy.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/phy/phy.c')
-rw-r--r--drivers/net/phy/phy.c194
1 files changed, 140 insertions, 54 deletions
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index c94a1fb3a4be..eed433d6056a 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -39,7 +39,9 @@
39#include <asm/irq.h> 39#include <asm/irq.h>
40#include <asm/uaccess.h> 40#include <asm/uaccess.h>
41 41
42/* Convenience function to print out the current phy status 42/**
43 * phy_print_status - Convenience function to print out the current phy status
44 * @phydev: the phy_device struct
43 */ 45 */
44void phy_print_status(struct phy_device *phydev) 46void phy_print_status(struct phy_device *phydev)
45{ 47{
@@ -55,10 +57,15 @@ void phy_print_status(struct phy_device *phydev)
55EXPORT_SYMBOL(phy_print_status); 57EXPORT_SYMBOL(phy_print_status);
56 58
57 59
58/* Convenience functions for reading/writing a given PHY 60/**
59 * register. They MUST NOT be called from interrupt context, 61 * phy_read - Convenience function for reading a given PHY register
62 * @phydev: the phy_device struct
63 * @regnum: register number to read
64 *
65 * NOTE: MUST NOT be called from interrupt context,
60 * because the bus read/write functions may wait for an interrupt 66 * because the bus read/write functions may wait for an interrupt
61 * to conclude the operation. */ 67 * to conclude the operation.
68 */
62int phy_read(struct phy_device *phydev, u16 regnum) 69int phy_read(struct phy_device *phydev, u16 regnum)
63{ 70{
64 int retval; 71 int retval;
@@ -72,6 +79,16 @@ int phy_read(struct phy_device *phydev, u16 regnum)
72} 79}
73EXPORT_SYMBOL(phy_read); 80EXPORT_SYMBOL(phy_read);
74 81
82/**
83 * phy_write - Convenience function for writing a given PHY register
84 * @phydev: the phy_device struct
85 * @regnum: register number to write
86 * @val: value to write to @regnum
87 *
88 * NOTE: MUST NOT be called from interrupt context,
89 * because the bus read/write functions may wait for an interrupt
90 * to conclude the operation.
91 */
75int phy_write(struct phy_device *phydev, u16 regnum, u16 val) 92int phy_write(struct phy_device *phydev, u16 regnum, u16 val)
76{ 93{
77 int err; 94 int err;
@@ -85,7 +102,15 @@ int phy_write(struct phy_device *phydev, u16 regnum, u16 val)
85} 102}
86EXPORT_SYMBOL(phy_write); 103EXPORT_SYMBOL(phy_write);
87 104
88 105/**
106 * phy_clear_interrupt - Ack the phy device's interrupt
107 * @phydev: the phy_device struct
108 *
109 * If the @phydev driver has an ack_interrupt function, call it to
110 * ack and clear the phy device's interrupt.
111 *
112 * Returns 0 on success on < 0 on error.
113 */
89int phy_clear_interrupt(struct phy_device *phydev) 114int phy_clear_interrupt(struct phy_device *phydev)
90{ 115{
91 int err = 0; 116 int err = 0;
@@ -96,7 +121,13 @@ int phy_clear_interrupt(struct phy_device *phydev)
96 return err; 121 return err;
97} 122}
98 123
99 124/**
125 * phy_config_interrupt - configure the PHY device for the requested interrupts
126 * @phydev: the phy_device struct
127 * @interrupts: interrupt flags to configure for this @phydev
128 *
129 * Returns 0 on success on < 0 on error.
130 */
100int phy_config_interrupt(struct phy_device *phydev, u32 interrupts) 131int phy_config_interrupt(struct phy_device *phydev, u32 interrupts)
101{ 132{
102 int err = 0; 133 int err = 0;
@@ -109,9 +140,11 @@ int phy_config_interrupt(struct phy_device *phydev, u32 interrupts)
109} 140}
110 141
111 142
112/* phy_aneg_done 143/**
144 * phy_aneg_done - return auto-negotiation status
145 * @phydev: target phy_device struct
113 * 146 *
114 * description: Reads the status register and returns 0 either if 147 * Description: Reads the status register and returns 0 either if
115 * auto-negotiation is incomplete, or if there was an error. 148 * auto-negotiation is incomplete, or if there was an error.
116 * Returns BMSR_ANEGCOMPLETE if auto-negotiation is done. 149 * Returns BMSR_ANEGCOMPLETE if auto-negotiation is done.
117 */ 150 */
@@ -173,9 +206,12 @@ static const struct phy_setting settings[] = {
173 206
174#define MAX_NUM_SETTINGS (sizeof(settings)/sizeof(struct phy_setting)) 207#define MAX_NUM_SETTINGS (sizeof(settings)/sizeof(struct phy_setting))
175 208
176/* phy_find_setting 209/**
210 * phy_find_setting - find a PHY settings array entry that matches speed & duplex
211 * @speed: speed to match
212 * @duplex: duplex to match
177 * 213 *
178 * description: Searches the settings array for the setting which 214 * Description: Searches the settings array for the setting which
179 * matches the desired speed and duplex, and returns the index 215 * matches the desired speed and duplex, and returns the index
180 * of that setting. Returns the index of the last setting if 216 * of that setting. Returns the index of the last setting if
181 * none of the others match. 217 * none of the others match.
@@ -192,11 +228,12 @@ static inline int phy_find_setting(int speed, int duplex)
192 return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1; 228 return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1;
193} 229}
194 230
195/* phy_find_valid 231/**
196 * idx: The first index in settings[] to search 232 * phy_find_valid - find a PHY setting that matches the requested features mask
197 * features: A mask of the valid settings 233 * @idx: The first index in settings[] to search
234 * @features: A mask of the valid settings
198 * 235 *
199 * description: Returns the index of the first valid setting less 236 * Description: Returns the index of the first valid setting less
200 * than or equal to the one pointed to by idx, as determined by 237 * than or equal to the one pointed to by idx, as determined by
201 * the mask in features. Returns the index of the last setting 238 * the mask in features. Returns the index of the last setting
202 * if nothing else matches. 239 * if nothing else matches.
@@ -209,11 +246,13 @@ static inline int phy_find_valid(int idx, u32 features)
209 return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1; 246 return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1;
210} 247}
211 248
212/* phy_sanitize_settings 249/**
250 * phy_sanitize_settings - make sure the PHY is set to supported speed and duplex
251 * @phydev: the target phy_device struct
213 * 252 *
214 * description: Make sure the PHY is set to supported speeds and 253 * Description: Make sure the PHY is set to supported speeds and
215 * duplexes. Drop down by one in this order: 1000/FULL, 254 * duplexes. Drop down by one in this order: 1000/FULL,
216 * 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF 255 * 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF.
217 */ 256 */
218void phy_sanitize_settings(struct phy_device *phydev) 257void phy_sanitize_settings(struct phy_device *phydev)
219{ 258{
@@ -232,16 +271,17 @@ void phy_sanitize_settings(struct phy_device *phydev)
232} 271}
233EXPORT_SYMBOL(phy_sanitize_settings); 272EXPORT_SYMBOL(phy_sanitize_settings);
234 273
235/* phy_ethtool_sset: 274/**
236 * A generic ethtool sset function. Handles all the details 275 * phy_ethtool_sset - generic ethtool sset function, handles all the details
276 * @phydev: target phy_device struct
277 * @cmd: ethtool_cmd
237 * 278 *
238 * A few notes about parameter checking: 279 * A few notes about parameter checking:
239 * - We don't set port or transceiver, so we don't care what they 280 * - We don't set port or transceiver, so we don't care what they
240 * were set to. 281 * were set to.
241 * - phy_start_aneg() will make sure forced settings are sane, and 282 * - phy_start_aneg() will make sure forced settings are sane, and
242 * choose the next best ones from the ones selected, so we don't 283 * choose the next best ones from the ones selected, so we don't
243 * care if ethtool tries to give us bad values 284 * care if ethtool tries to give us bad values.
244 *
245 */ 285 */
246int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd) 286int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd)
247{ 287{
@@ -304,9 +344,15 @@ int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd)
304} 344}
305EXPORT_SYMBOL(phy_ethtool_gset); 345EXPORT_SYMBOL(phy_ethtool_gset);
306 346
307/* Note that this function is currently incompatible with the 347/**
348 * phy_mii_ioctl - generic PHY MII ioctl interface
349 * @phydev: the phy_device struct
350 * @mii_data: MII ioctl data
351 * @cmd: ioctl cmd to execute
352 *
353 * Note that this function is currently incompatible with the
308 * PHYCONTROL layer. It changes registers without regard to 354 * PHYCONTROL layer. It changes registers without regard to
309 * current state. Use at own risk 355 * current state. Use at own risk.
310 */ 356 */
311int phy_mii_ioctl(struct phy_device *phydev, 357int phy_mii_ioctl(struct phy_device *phydev,
312 struct mii_ioctl_data *mii_data, int cmd) 358 struct mii_ioctl_data *mii_data, int cmd)
@@ -336,6 +382,12 @@ int phy_mii_ioctl(struct phy_device *phydev,
336 phydev->duplex = DUPLEX_FULL; 382 phydev->duplex = DUPLEX_FULL;
337 else 383 else
338 phydev->duplex = DUPLEX_HALF; 384 phydev->duplex = DUPLEX_HALF;
385 if ((!phydev->autoneg) &&
386 (val & BMCR_SPEED1000))
387 phydev->speed = SPEED_1000;
388 else if ((!phydev->autoneg) &&
389 (val & BMCR_SPEED100))
390 phydev->speed = SPEED_100;
339 break; 391 break;
340 case MII_ADVERTISE: 392 case MII_ADVERTISE:
341 phydev->advertising = val; 393 phydev->advertising = val;
@@ -358,13 +410,14 @@ int phy_mii_ioctl(struct phy_device *phydev,
358 return 0; 410 return 0;
359} 411}
360 412
361/* phy_start_aneg 413/**
414 * phy_start_aneg - start auto-negotiation for this PHY device
415 * @phydev: the phy_device struct
362 * 416 *
363 * description: Sanitizes the settings (if we're not 417 * Description: Sanitizes the settings (if we're not autonegotiating
364 * autonegotiating them), and then calls the driver's 418 * them), and then calls the driver's config_aneg function.
365 * config_aneg function. If the PHYCONTROL Layer is operating, 419 * If the PHYCONTROL Layer is operating, we change the state to
366 * we change the state to reflect the beginning of 420 * reflect the beginning of Auto-negotiation or forcing.
367 * Auto-negotiation or forcing.
368 */ 421 */
369int phy_start_aneg(struct phy_device *phydev) 422int phy_start_aneg(struct phy_device *phydev)
370{ 423{
@@ -400,15 +453,19 @@ EXPORT_SYMBOL(phy_start_aneg);
400static void phy_change(struct work_struct *work); 453static void phy_change(struct work_struct *work);
401static void phy_timer(unsigned long data); 454static void phy_timer(unsigned long data);
402 455
403/* phy_start_machine: 456/**
457 * phy_start_machine - start PHY state machine tracking
458 * @phydev: the phy_device struct
459 * @handler: callback function for state change notifications
404 * 460 *
405 * description: The PHY infrastructure can run a state machine 461 * Description: The PHY infrastructure can run a state machine
406 * which tracks whether the PHY is starting up, negotiating, 462 * which tracks whether the PHY is starting up, negotiating,
407 * etc. This function starts the timer which tracks the state 463 * etc. This function starts the timer which tracks the state
408 * of the PHY. If you want to be notified when the state 464 * of the PHY. If you want to be notified when the state changes,
409 * changes, pass in the callback, otherwise, pass NULL. If you 465 * pass in the callback @handler, otherwise, pass NULL. If you
410 * want to maintain your own state machine, do not call this 466 * want to maintain your own state machine, do not call this
411 * function. */ 467 * function.
468 */
412void phy_start_machine(struct phy_device *phydev, 469void phy_start_machine(struct phy_device *phydev,
413 void (*handler)(struct net_device *)) 470 void (*handler)(struct net_device *))
414{ 471{
@@ -420,9 +477,11 @@ void phy_start_machine(struct phy_device *phydev,
420 mod_timer(&phydev->phy_timer, jiffies + HZ); 477 mod_timer(&phydev->phy_timer, jiffies + HZ);
421} 478}
422 479
423/* phy_stop_machine 480/**
481 * phy_stop_machine - stop the PHY state machine tracking
482 * @phydev: target phy_device struct
424 * 483 *
425 * description: Stops the state machine timer, sets the state to UP 484 * Description: Stops the state machine timer, sets the state to UP
426 * (unless it wasn't up yet). This function must be called BEFORE 485 * (unless it wasn't up yet). This function must be called BEFORE
427 * phy_detach. 486 * phy_detach.
428 */ 487 */
@@ -438,12 +497,14 @@ void phy_stop_machine(struct phy_device *phydev)
438 phydev->adjust_state = NULL; 497 phydev->adjust_state = NULL;
439} 498}
440 499
441/* phy_force_reduction 500/**
501 * phy_force_reduction - reduce PHY speed/duplex settings by one step
502 * @phydev: target phy_device struct
442 * 503 *
443 * description: Reduces the speed/duplex settings by 504 * Description: Reduces the speed/duplex settings by one notch,
444 * one notch. The order is so: 505 * in this order--
445 * 1000/FULL, 1000/HALF, 100/FULL, 100/HALF, 506 * 1000/FULL, 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF.
446 * 10/FULL, 10/HALF. The function bottoms out at 10/HALF. 507 * The function bottoms out at 10/HALF.
447 */ 508 */
448static void phy_force_reduction(struct phy_device *phydev) 509static void phy_force_reduction(struct phy_device *phydev)
449{ 510{
@@ -464,7 +525,9 @@ static void phy_force_reduction(struct phy_device *phydev)
464} 525}
465 526
466 527
467/* phy_error: 528/**
529 * phy_error - enter HALTED state for this PHY device
530 * @phydev: target phy_device struct
468 * 531 *
469 * Moves the PHY to the HALTED state in response to a read 532 * Moves the PHY to the HALTED state in response to a read
470 * or write error, and tells the controller the link is down. 533 * or write error, and tells the controller the link is down.
@@ -478,9 +541,12 @@ void phy_error(struct phy_device *phydev)
478 spin_unlock(&phydev->lock); 541 spin_unlock(&phydev->lock);
479} 542}
480 543
481/* phy_interrupt 544/**
545 * phy_interrupt - PHY interrupt handler
546 * @irq: interrupt line
547 * @phy_dat: phy_device pointer
482 * 548 *
483 * description: When a PHY interrupt occurs, the handler disables 549 * Description: When a PHY interrupt occurs, the handler disables
484 * interrupts, and schedules a work task to clear the interrupt. 550 * interrupts, and schedules a work task to clear the interrupt.
485 */ 551 */
486static irqreturn_t phy_interrupt(int irq, void *phy_dat) 552static irqreturn_t phy_interrupt(int irq, void *phy_dat)
@@ -501,7 +567,10 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
501 return IRQ_HANDLED; 567 return IRQ_HANDLED;
502} 568}
503 569
504/* Enable the interrupts from the PHY side */ 570/**
571 * phy_enable_interrupts - Enable the interrupts from the PHY side
572 * @phydev: target phy_device struct
573 */
505int phy_enable_interrupts(struct phy_device *phydev) 574int phy_enable_interrupts(struct phy_device *phydev)
506{ 575{
507 int err; 576 int err;
@@ -517,7 +586,10 @@ int phy_enable_interrupts(struct phy_device *phydev)
517} 586}
518EXPORT_SYMBOL(phy_enable_interrupts); 587EXPORT_SYMBOL(phy_enable_interrupts);
519 588
520/* Disable the PHY interrupts from the PHY side */ 589/**
590 * phy_disable_interrupts - Disable the PHY interrupts from the PHY side
591 * @phydev: target phy_device struct
592 */
521int phy_disable_interrupts(struct phy_device *phydev) 593int phy_disable_interrupts(struct phy_device *phydev)
522{ 594{
523 int err; 595 int err;
@@ -543,13 +615,15 @@ phy_err:
543} 615}
544EXPORT_SYMBOL(phy_disable_interrupts); 616EXPORT_SYMBOL(phy_disable_interrupts);
545 617
546/* phy_start_interrupts 618/**
619 * phy_start_interrupts - request and enable interrupts for a PHY device
620 * @phydev: target phy_device struct
547 * 621 *
548 * description: Request the interrupt for the given PHY. If 622 * Description: Request the interrupt for the given PHY.
549 * this fails, then we set irq to PHY_POLL. 623 * If this fails, then we set irq to PHY_POLL.
550 * Otherwise, we enable the interrupts in the PHY. 624 * Otherwise, we enable the interrupts in the PHY.
551 * Returns 0 on success.
552 * This should only be called with a valid IRQ number. 625 * This should only be called with a valid IRQ number.
626 * Returns 0 on success or < 0 on error.
553 */ 627 */
554int phy_start_interrupts(struct phy_device *phydev) 628int phy_start_interrupts(struct phy_device *phydev)
555{ 629{
@@ -574,6 +648,10 @@ int phy_start_interrupts(struct phy_device *phydev)
574} 648}
575EXPORT_SYMBOL(phy_start_interrupts); 649EXPORT_SYMBOL(phy_start_interrupts);
576 650
651/**
652 * phy_stop_interrupts - disable interrupts from a PHY device
653 * @phydev: target phy_device struct
654 */
577int phy_stop_interrupts(struct phy_device *phydev) 655int phy_stop_interrupts(struct phy_device *phydev)
578{ 656{
579 int err; 657 int err;
@@ -596,7 +674,10 @@ int phy_stop_interrupts(struct phy_device *phydev)
596EXPORT_SYMBOL(phy_stop_interrupts); 674EXPORT_SYMBOL(phy_stop_interrupts);
597 675
598 676
599/* Scheduled by the phy_interrupt/timer to handle PHY changes */ 677/**
678 * phy_change - Scheduled by the phy_interrupt/timer to handle PHY changes
679 * @work: work_struct that describes the work to be done
680 */
600static void phy_change(struct work_struct *work) 681static void phy_change(struct work_struct *work)
601{ 682{
602 int err; 683 int err;
@@ -630,7 +711,10 @@ phy_err:
630 phy_error(phydev); 711 phy_error(phydev);
631} 712}
632 713
633/* Bring down the PHY link, and stop checking the status. */ 714/**
715 * phy_stop - Bring down the PHY link, and stop checking the status
716 * @phydev: target phy_device struct
717 */
634void phy_stop(struct phy_device *phydev) 718void phy_stop(struct phy_device *phydev)
635{ 719{
636 spin_lock(&phydev->lock); 720 spin_lock(&phydev->lock);
@@ -659,9 +743,11 @@ out_unlock:
659} 743}
660 744
661 745
662/* phy_start 746/**
747 * phy_start - start or restart a PHY device
748 * @phydev: target phy_device struct
663 * 749 *
664 * description: Indicates the attached device's readiness to 750 * Description: Indicates the attached device's readiness to
665 * handle PHY-related work. Used during startup to start the 751 * handle PHY-related work. Used during startup to start the
666 * PHY, and after a call to phy_stop() to resume operation. 752 * PHY, and after a call to phy_stop() to resume operation.
667 * Also used to indicate the MDIO bus has cleared an error 753 * Also used to indicate the MDIO bus has cleared an error