1 /*
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
6 *
7 * Author: Andy Fleming
8 *
9 * Copyright (c) 2004 Freescale Semiconductor, Inc.
10 *
11 * 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 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 */
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
19 #include <linux/string.h>
20 #include <linux/errno.h>
21 #include <linux/unistd.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/netdevice.h>
27 #include <linux/etherdevice.h>
28 #include <linux/skbuff.h>
29 #include <linux/spinlock.h>
30 #include <linux/mm.h>
31 #include <linux/module.h>
32 #include <linux/mii.h>
33 #include <linux/ethtool.h>
34 #include <linux/phy.h>
35
36 #include <asm/io.h>
37 #include <asm/irq.h>
38 #include <asm/uaccess.h>
39
40 /* Convenience function to print out the current phy status
41 */
42 void phy_print_status(struct phy_device *phydev)
43 {
44 pr_info("PHY: %s - Link is %s", phydev->dev.bus_id,
45 phydev->link ? "Up" : "Down");
46 if (phydev->link)
47 printk(" - %d/%s", phydev->speed,
48 DUPLEX_FULL == phydev->duplex ?
49 "Full" : "Half");
50
51 printk("\n");
52 }
53 EXPORT_SYMBOL(phy_print_status);
54
55
56 /* Convenience functions for reading/writing a given PHY
57 * register. They MUST NOT be called from interrupt context,
58 * because the bus read/write functions may wait for an interrupt
59 * to conclude the operation. */
60 int phy_read(struct phy_device *phydev, u16 regnum)
61 {
62 int retval;
63 struct mii_bus *bus = phydev->bus;
64
65 spin_lock_bh(&bus->mdio_lock);
66 retval = bus->read(bus, phydev->addr, regnum);
67 spin_unlock_bh(&bus->mdio_lock);
68
69 return retval;
70 }
71 EXPORT_SYMBOL(phy_read);
72
73 int phy_write(struct phy_device *phydev, u16 regnum, u16 val)
74 {
75 int err;
76 struct mii_bus *bus = phydev->bus;
77
78 spin_lock_bh(&bus->mdio_lock);
79 err = bus->write(bus, phydev->addr, regnum, val);
80 spin_unlock_bh(&bus->mdio_lock);
81
82 return err;
83 }
84 EXPORT_SYMBOL(phy_write);
85
86
87 int phy_clear_interrupt(struct phy_device *phydev)
88 {
89 int err = 0;
90
91 if (phydev->drv->ack_interrupt)
92 err = phydev->drv->ack_interrupt(phydev);
93
94 return err;
95 }
96
97
98 int phy_config_interrupt(struct phy_device *phydev, u32 interrupts)
99 {
100 int err = 0;
101
102 phydev->interrupts = interrupts;
103 if (phydev->drv->config_intr)
104 err = phydev->drv->config_intr(phydev);
105
106 return err;
107 }
108
109
110 /* phy_aneg_done
111 *
112 * description: Reads the status register and returns 0 either if
113 * auto-negotiation is incomplete, or if there was an error.
114 * Returns BMSR_ANEGCOMPLETE if auto-negotiation is done.
115 */
116 static inline int phy_aneg_done(struct phy_device *phydev)
117 {
118 int retval;
119
120 retval = phy_read(phydev, MII_BMSR);
121
122 return (retval < 0) ? retval : (retval & BMSR_ANEGCOMPLETE);
123 }
124
125 /* A structure for mapping a particular speed and duplex
126 * combination to a particular SUPPORTED and ADVERTISED value */
127 struct phy_setting {
128 int speed;
129 int duplex;
130 u32 setting;
131 };
132
133 /* A mapping of all SUPPORTED settings to speed/duplex */
134 static const struct phy_setting settings[] = {
135 {
136 .speed = 10000,
137 .duplex = DUPLEX_FULL,
138 .setting = SUPPORTED_10000baseT_Full,
139 },
140 {
141 .speed = SPEED_1000,
142 .duplex = DUPLEX_FULL,
143 .setting = SUPPORTED_1000baseT_Full,
144 },
145 {
146 .speed = SPEED_1000,
147 .duplex = DUPLEX_HALF,
148 .setting = SUPPORTED_1000baseT_Half,
149 },
150 {
151 .speed = SPEED_100,
152 .duplex = DUPLEX_FULL,
153 .setting = SUPPORTED_100baseT_Full,
154 },
155 {
156 .speed = SPEED_100,
157 .duplex = DUPLEX_HALF,
158 .setting = SUPPORTED_100baseT_Half,
159 },
160 {
161 .speed = SPEED_10,
162 .duplex = DUPLEX_FULL,
163 .setting = SUPPORTED_10baseT_Full,
164 },
165 {
166 .speed = SPEED_10,
167 .duplex = DUPLEX_HALF,
168 .setting = SUPPORTED_10baseT_Half,
169 },
170 };
171
172 #define MAX_NUM_SETTINGS (sizeof(settings)/sizeof(struct phy_setting))
173
174 /* phy_find_setting
175 *
176 * description: Searches the settings array for the setting which
177 * matches the desired speed and duplex, and returns the index
178 * of that setting. Returns the index of the last setting if
179 * none of the others match.
180 */
181 static inline int phy_find_setting(int speed, int duplex)
182 {
183 int idx = 0;
184
185 while (idx < ARRAY_SIZE(settings) &&
186 (settings[idx].speed != speed ||
187 settings[idx].duplex != duplex))
188 idx++;
189
190 return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1;
191 }
192
193 /* phy_find_valid
194 * idx: The first index in settings[] to search
195 * features: A mask of the valid settings
196 *
197 * description: Returns the index of the first valid setting less
198 * than or equal to the one pointed to by idx, as determined by
199 * the mask in features. Returns the index of the last setting
200 * if nothing else matches.
201 */
202 static inline int phy_find_valid(int idx, u32 features)
203 {
204 while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features))
205 idx++;
206
207 return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1;
208 }
209
210 /* phy_sanitize_settings
211 *
212 * description: Make sure the PHY is set to supported speeds and
213 * duplexes. Drop down by one in this order: 1000/FULL,
214 * 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF
215 */
216 void phy_sanitize_settings(struct phy_device *phydev)
217 {
218 u32 features = phydev->supported;
219 int idx;
220
221 /* Sanitize settings based on PHY capabilities */
222 if ((features & SUPPORTED_Autoneg) == 0)
223 phydev->autoneg = 0;
224
225 idx = phy_find_valid(phy_find_setting(phydev->speed, phydev->duplex),
226 features);
227
228 phydev->speed = settings[idx].speed;
229 phydev->duplex = settings[idx].duplex;
230 }
231 EXPORT_SYMBOL(phy_sanitize_settings);
232
233 /* phy_ethtool_sset:
234 * A generic ethtool sset function. Handles all the details
235 *
236 * A few notes about parameter checking:
237 * - We don't set port or transceiver, so we don't care what they
238 * were set to.
239 * - phy_start_aneg() will make sure forced settings are sane, and
240 * choose the next best ones from the ones selected, so we don't
241 * care if ethtool tries to give us bad values
242 *
243 */
244 int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd)
245 {
246 if (cmd->phy_address != phydev->addr)
247 return -EINVAL;
248
249 /* We make sure that we don't pass unsupported
250 * values in to the PHY */
251 cmd->advertising &= phydev->supported;
252
253 /* Verify the settings we care about. */
254 if (cmd->autoneg != AUTONEG_ENABLE && cmd->autoneg != AUTONEG_DISABLE)
255 return -EINVAL;
256
257 if (cmd->autoneg == AUTONEG_ENABLE && cmd->advertising == 0)
258 return -EINVAL;
259
260 if (cmd->autoneg == AUTONEG_DISABLE
261 && ((cmd->speed != SPEED_1000
262 && cmd->speed != SPEED_100
263 && cmd->speed != SPEED_10)
264 || (cmd->duplex != DUPLEX_HALF
265 && cmd->duplex != DUPLEX_FULL)))
266 return -EINVAL;
267
268 phydev->autoneg = cmd->autoneg;
269
270 phydev->speed = cmd->speed;
271
272 phydev->advertising = cmd->advertising;
273
274 if (AUTONEG_ENABLE == cmd->autoneg)
275 phydev->advertising |= ADVERTISED_Autoneg;
276 else
277 phydev->advertising &= ~ADVERTISED_Autoneg;
278
279 phydev->duplex = cmd->duplex;
280
281 /* Restart the PHY */
282 phy_start_aneg(phydev);
283
284 return 0;
285 }
286 EXPORT_SYMBOL(phy_ethtool_sset);
287
288 int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd)
289 {
290 cmd->supported = phydev->supported;
291
292 cmd->advertising = phydev->advertising;
293
294 cmd->speed = phydev->speed;
295 cmd->duplex = phydev->duplex;
296 cmd->port = PORT_MII;
297 cmd->phy_address = phydev->addr;
298 cmd->transceiver = XCVR_EXTERNAL;
299 cmd->autoneg = phydev->autoneg;
300
301 return 0;
302 }
303 EXPORT_SYMBOL(phy_ethtool_gset);
304
305 /* Note that this function is currently incompatible with the
306 * PHYCONTROL layer. It changes registers without regard to
307 * current state. Use at own risk
308 */
309 int phy_mii_ioctl(struct phy_device *phydev,
310 struct mii_ioctl_data *mii_data, int cmd)
311 {
312 u16 val = mii_data->val_in;
313
314 switch (cmd) {
315 case SIOCGMIIPHY:
316 mii_data->phy_id = phydev->addr;
317 break;
318 case SIOCGMIIREG:
319 mii_data->val_out = phy_read(phydev, mii_data->reg_num);
320 break;
321
322 case SIOCSMIIREG:
323 if (!capable(CAP_NET_ADMIN))
324 return -EPERM;
325
326 if (mii_data->phy_id == phydev->addr) {
327 switch(mii_data->reg_num) {
328 case MII_BMCR:
329 if (val & (BMCR_RESET|BMCR_ANENABLE))
330 phydev->autoneg = AUTONEG_DISABLE;
331 else
332 phydev->autoneg = AUTONEG_ENABLE;
333 if ((!phydev->autoneg) && (val & BMCR_FULLDPLX))
334 phydev->duplex = DUPLEX_FULL;
335 else
336 phydev->duplex = DUPLEX_HALF;
337 break;
338 case MII_ADVERTISE:
339 phydev->advertising = val;
340 break;
341 default:
342 /* do nothing */
343 break;
344 }
345 }
346
347 phy_write(phydev, mii_data->reg_num, val);
348
349 if (mii_data->reg_num == MII_BMCR
350 && val & BMCR_RESET
351 && phydev->drv->config_init)
352 phydev->drv->config_init(phydev);
353 break;
354 }
355
356 return 0;
357 }
358 EXPORT_SYMBOL(phy_mii_ioctl);
359
360 /* phy_start_aneg
361 *
362 * description: Sanitizes the settings (if we're not
363 * autonegotiating them), and then calls the driver's
364 * config_aneg function. If the PHYCONTROL Layer is operating,
365 * we change the state to reflect the beginning of
366 * Auto-negotiation or forcing.
367 */
368 int phy_start_aneg(struct phy_device *phydev)
369 {
370 int err;
371
372 spin_lock(&phydev->lock);
373
374 if (AUTONEG_DISABLE == phydev->autoneg)
375 phy_sanitize_settings(phydev);
376
377 err = phydev->drv->config_aneg(phydev);
378
379 if (err < 0)
380 goto out_unlock;
381
382 if (phydev->state != PHY_HALTED) {
383 if (AUTONEG_ENABLE == phydev->autoneg) {
384 phydev->state = PHY_AN;
385 phydev->link_timeout = PHY_AN_TIMEOUT;
386 } else {
387 phydev->state = PHY_FORCING;
388 phydev->link_timeout = PHY_FORCE_TIMEOUT;
389 }
390 }
391
392 out_unlock:
393 spin_unlock(&phydev->lock);
394 return err;
395 }
396 EXPORT_SYMBOL(phy_start_aneg);
397
398
399 static void phy_change(void *data);
400 static void phy_timer(unsigned long data);
401
402 /* phy_start_machine:
403 *
404 * description: The PHY infrastructure can run a state machine
405 * which tracks whether the PHY is starting up, negotiating,
406 * etc. This function starts the timer which tracks the state
407 * of the PHY. If you want to be notified when the state
408 * changes, pass in the callback, otherwise, pass NULL. If you
409 * want to maintain your own state machine, do not call this
410 * function. */
411 void phy_start_machine(struct phy_device *phydev,
412 void (*handler)(struct net_device *))
413 {
414 phydev->adjust_state = handler;
415
416 init_timer(&phydev->phy_timer);
417 phydev->phy_timer.function = &phy_timer;
418 phydev->phy_timer.data = (unsigned long) phydev;
419 mod_timer(&phydev->phy_timer, jiffies + HZ);
420 }
421
422 /* phy_stop_machine
423 *
424 * description: Stops the state machine timer, sets the state to UP
425 * (unless it wasn't up yet). This function must be called BEFORE
426 * phy_detach.
427 */
428 void phy_stop_machine(struct phy_device *phydev)
429 {
430 del_timer_sync(&phydev->phy_timer);
431
432 spin_lock(&phydev->lock);
433 if (phydev->state > PHY_UP)
434 phydev->state = PHY_UP;
435 spin_unlock(&phydev->lock);
436
437 phydev->adjust_state = NULL;
438 }
439
440 /* phy_force_reduction
441 *
442 * description: Reduces the speed/duplex settings by
443 * one notch. The order is so:
444 * 1000/FULL, 1000/HALF, 100/FULL, 100/HALF,
445 * 10/FULL, 10/HALF. The function bottoms out at 10/HALF.
446 */
447 static void phy_force_reduction(struct phy_device *phydev)
448 {
449 int idx;
450
451 idx = phy_find_setting(phydev->speed, phydev->duplex);
452
453 idx++;
454
455 idx = phy_find_valid(idx, phydev->supported);
456
457 phydev->speed = settings[idx].speed;
458 phydev->duplex = settings[idx].duplex;
459
460 pr_info("Trying %d/%s\n", phydev->speed,
461 DUPLEX_FULL == phydev->duplex ?
462 "FULL" : "HALF");
463 }
464
465
466 /* phy_error:
467 *
468 * Moves the PHY to the HALTED state in response to a read
469 * or write error, and tells the controller the link is down.
470 * Must not be called from interrupt context, or while the
471 * phydev->lock is held.
472 */
473 void phy_error(struct phy_device *phydev)
474 {
475 spin_lock(&phydev->lock);
476 phydev->state = PHY_HALTED;
477 spin_unlock(&phydev->lock);
478 }
479
480 /* phy_interrupt
481 *
482 * description: When a PHY interrupt occurs, the handler disables
483 * interrupts, and schedules a work task to clear the interrupt.
484 */
485 static irqreturn_t phy_interrupt(int irq, void *phy_dat, struct pt_regs *regs)
486 {
487 struct phy_device *phydev = phy_dat;
488
489 /* The MDIO bus is not allowed to be written in interrupt
490 * context, so we need to disable the irq here. A work
491 * queue will write the PHY to disable and clear the
492 * interrupt, and then reenable the irq line. */
493 disable_irq_nosync(irq);
494
495 schedule_work(&phydev->phy_queue);
496
497 return IRQ_HANDLED;
498 }
499
500 /* Enable the interrupts from the PHY side */
501 int phy_enable_interrupts(struct phy_device *phydev)
502 {
503 int err;
504
505 err = phy_clear_interrupt(phydev);
506
507 if (err < 0)
508 return err;
509
510 err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED);
511
512 return err;
513 }
514 EXPORT_SYMBOL(phy_enable_interrupts);
515
516 /* Disable the PHY interrupts from the PHY side */
517 int phy_disable_interrupts(struct phy_device *phydev)
518 {
519 int err;
520
521 /* Disable PHY interrupts */
522 err = phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED);
523
524 if (err)
525 goto phy_err;
526
527 /* Clear the interrupt */
528 err = phy_clear_interrupt(phydev);
529
530 if (err)
531 goto phy_err;
532
533 return 0;
534
535 phy_err:
536 phy_error(phydev);
537
538 return err;
539 }
540 EXPORT_SYMBOL(phy_disable_interrupts);
541
542 /* phy_start_interrupts
543 *
544 * description: Request the interrupt for the given PHY. If
545 * this fails, then we set irq to PHY_POLL.
546 * Otherwise, we enable the interrupts in the PHY.
547 * Returns 0 on success.
548 * This should only be called with a valid IRQ number.
549 */
550 int phy_start_interrupts(struct phy_device *phydev)
551 {
552 int err = 0;
553
554 INIT_WORK(&phydev->phy_queue, phy_change, phydev);
555
556 if (request_irq(phydev->irq, phy_interrupt,
557 IRQF_SHARED,
558 "phy_interrupt",
559 phydev) < 0) {
560 printk(KERN_WARNING "%s: Can't get IRQ %d (PHY)\n",
561 phydev->bus->name,
562 phydev->irq);
563 phydev->irq = PHY_POLL;
564 return 0;
565 }
566
567 err = phy_enable_interrupts(phydev);
568
569 return err;
570 }
571 EXPORT_SYMBOL(phy_start_interrupts);
572
573 int phy_stop_interrupts(struct phy_device *phydev)
574 {
575 int err;
576
577 err = phy_disable_interrupts(phydev);
578
579 if (err)
580 phy_error(phydev);
581
582 free_irq(phydev->irq, phydev);
583
584 return err;
585 }
586 EXPORT_SYMBOL(phy_stop_interrupts);
587
588
589 /* Scheduled by the phy_interrupt/timer to handle PHY changes */
590 static void phy_change(void *data)
591 {
592 int err;
593 struct phy_device *phydev = data;
594
595 err = phy_disable_interrupts(phydev);
596
597 if (err)
598 goto phy_err;
599
600 spin_lock(&phydev->lock);
601 if ((PHY_RUNNING == phydev->state) || (PHY_NOLINK == phydev->state))
602 phydev->state = PHY_CHANGELINK;
603 spin_unlock(&phydev->lock);
604
605 enable_irq(phydev->irq);
606
607 /* Reenable interrupts */
608 err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED);
609
610 if (err)
611 goto irq_enable_err;
612
613 return;
614
615 irq_enable_err:
616 disable_irq(phydev->irq);
617 phy_err:
618 phy_error(phydev);
619 }
620
621 /* Bring down the PHY link, and stop checking the status. */
622 void phy_stop(struct phy_device *phydev)
623 {
624 spin_lock(&phydev->lock);
625
626 if (PHY_HALTED == phydev->state)
627 goto out_unlock;
628
629 if (phydev->irq != PHY_POLL) {
630 /* Clear any pending interrupts */
631 phy_clear_interrupt(phydev);
632
633 /* Disable PHY Interrupts */
634 phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED);
635 }
636
637 phydev->state = PHY_HALTED;
638
639 out_unlock:
640 spin_unlock(&phydev->lock);
641 }
642
643
644 /* phy_start
645 *
646 * description: Indicates the attached device's readiness to
647 * handle PHY-related work. Used during startup to start the
648 * PHY, and after a call to phy_stop() to resume operation.
649 * Also used to indicate the MDIO bus has cleared an error
650 * condition.
651 */
652 void phy_start(struct phy_device *phydev)
653 {
654 spin_lock(&phydev->lock);
655
656 switch (phydev->state) {
657 case PHY_STARTING:
658 phydev->state = PHY_PENDING;
659 break;
660 case PHY_READY:
661 phydev->state = PHY_UP;
662 break;
663 case PHY_HALTED:
664 phydev->state = PHY_RESUMING;
665 default:
666 break;
667 }
668 spin_unlock(&phydev->lock);
669 }
670 EXPORT_SYMBOL(phy_stop);
671 EXPORT_SYMBOL(phy_start);
672
673 /* PHY timer which handles the state machine */
674 static void phy_timer(unsigned long data)
675 {
676 struct phy_device *phydev = (struct phy_device *)data;
677 int needs_aneg = 0;
678 int err = 0;
679
680 spin_lock(&phydev->lock);
681
682 if (phydev->adjust_state)
683 phydev->adjust_state(phydev->attached_dev);
684
685 switch(phydev->state) {
686 case PHY_DOWN:
687 case PHY_STARTING:
688 case PHY_READY:
689 case PHY_PENDING:
690 break;
691 case PHY_UP:
692 needs_aneg = 1;
693
694 phydev->link_timeout = PHY_AN_TIMEOUT;
695
696 break;
697 case PHY_AN:
698 /* Check if negotiation is done. Break
699 * if there's an error */
700 err = phy_aneg_done(phydev);
701 if (err < 0)
702 break;
703
704 /* If auto-negotiation is done, we change to
705 * either RUNNING, or NOLINK */
706 if (err > 0) {
707 err = phy_read_status(phydev);
708
709 if (err)
710 break;
711
712 if (phydev->link) {
713 phydev->state = PHY_RUNNING;
714 netif_carrier_on(phydev->attached_dev);
715 } else {
716 phydev->state = PHY_NOLINK;
717 netif_carrier_off(phydev->attached_dev);
718 }
719
720 phydev->adjust_link(phydev->attached_dev);
721
722 } else if (0 == phydev->link_timeout--) {
723 /* The counter expired, so either we
724 * switch to forced mode, or the
725 * magic_aneg bit exists, and we try aneg
726 * again */
727 if (!(phydev->drv->flags & PHY_HAS_MAGICANEG)) {
728 int idx;
729
730 /* We'll start from the
731 * fastest speed, and work
732 * our way down */
733 idx = phy_find_valid(0,
734 phydev->supported);
735
736 phydev->speed = settings[idx].speed;
737 phydev->duplex = settings[idx].duplex;
738
739 phydev->autoneg = AUTONEG_DISABLE;
740 phydev->state = PHY_FORCING;
741 phydev->link_timeout =
742 PHY_FORCE_TIMEOUT;
743
744 pr_info("Trying %d/%s\n",
745 phydev->speed,
746 DUPLEX_FULL ==
747 phydev->duplex ?
748 "FULL" : "HALF");
749 }
750
751 needs_aneg = 1;
752 }
753 break;
754 case PHY_NOLINK:
755 err = phy_read_status(phydev);
756
757 if (err)
758 break;
759
760 if (phydev->link) {
761 phydev->state = PHY_RUNNING;
762 netif_carrier_on(phydev->attached_dev);
763 phydev->adjust_link(phydev->attached_dev);
764 }
765 break;
766 case PHY_FORCING:
767 err = phy_read_status(phydev);
768
769 if (err)
770 break;
771
772 if (phydev->link) {
773 phydev->state = PHY_RUNNING;
774 netif_carrier_on(phydev->attached_dev);
775 } else {
776 if (0 == phydev->link_timeout--) {
777 phy_force_reduction(phydev);
778 needs_aneg = 1;
779 }
780 }
781
782 phydev->adjust_link(phydev->attached_dev);
783 break;
784 case PHY_RUNNING:
785 /* Only register a CHANGE if we are
786 * polling */
787 if (PHY_POLL == phydev->irq)
788 phydev->state = PHY_CHANGELINK;
789 break;
790 case PHY_CHANGELINK:
791 err = phy_read_status(phydev);
792
793 if (err)
794 break;
795
796 if (phydev->link) {
797 phydev->state = PHY_RUNNING;
798 netif_carrier_on(phydev->attached_dev);
799 } else {
800 phydev->state = PHY_NOLINK;
801 netif_carrier_off(phydev->attached_dev);
802 }
803
804 phydev->adjust_link(phydev->attached_dev);
805
806 if (PHY_POLL != phydev->irq)
807 err = phy_config_interrupt(phydev,
808 PHY_INTERRUPT_ENABLED);
809 break;
810 case PHY_HALTED:
811 if (phydev->link) {
812 phydev->link = 0;
813 netif_carrier_off(phydev->attached_dev);
814 phydev->adjust_link(phydev->attached_dev);
815 }
816 break;
817 case PHY_RESUMING:
818
819 err = phy_clear_interrupt(phydev);
820
821 if (err)
822 break;
823
824 err = phy_config_interrupt(phydev,
825 PHY_INTERRUPT_ENABLED);
826
827 if (err)
828 break;
829
830 if (AUTONEG_ENABLE == phydev->autoneg) {
831 err = phy_aneg_done(phydev);
832 if (err < 0)
833 break;
834
835 /* err > 0 if AN is done.
836 * Otherwise, it's 0, and we're
837 * still waiting for AN */
838 if (err > 0) {
839 phydev->state = PHY_RUNNING;
840 } else {
841 phydev->state = PHY_AN;
842 phydev->link_timeout = PHY_AN_TIMEOUT;
843 }
844 } else
845 phydev->state = PHY_RUNNING;
846 break;
847 }
848
849 spin_unlock(&phydev->lock);
850
851 if (needs_aneg)
852 err = phy_start_aneg(phydev);
853
854 if (err < 0)
855 phy_error(phydev);
856
857 mod_timer(&phydev->phy_timer, jiffies + PHY_STATE_TIME * HZ);
858 }
859
860
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.