1 /* Framework for finding and configuring PHYs.
2 * Also contains generic PHY driver
6 * Copyright (c) 2004 Freescale Semiconductor, Inc.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 #include <linux/kernel.h>
18 #include <linux/string.h>
19 #include <linux/errno.h>
20 #include <linux/unistd.h>
21 #include <linux/slab.h>
22 #include <linux/interrupt.h>
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/skbuff.h>
29 #include <linux/module.h>
30 #include <linux/mii.h>
31 #include <linux/ethtool.h>
32 #include <linux/phy.h>
33 #include <linux/mdio.h>
35 #include <linux/uaccess.h>
40 MODULE_DESCRIPTION("PHY library");
41 MODULE_AUTHOR("Andy Fleming");
42 MODULE_LICENSE("GPL");
44 void phy_device_free(struct phy_device
*phydev
)
46 put_device(&phydev
->mdio
.dev
);
48 EXPORT_SYMBOL(phy_device_free
);
50 static void phy_device_release(struct device
*dev
)
52 kfree(to_phy_device(dev
));
61 static struct phy_driver genphy_driver
[GENPHY_DRV_MAX
];
63 static LIST_HEAD(phy_fixup_list
);
64 static DEFINE_MUTEX(phy_fixup_lock
);
67 static bool mdio_bus_phy_may_suspend(struct phy_device
*phydev
)
69 struct device_driver
*drv
= phydev
->mdio
.dev
.driver
;
70 struct phy_driver
*phydrv
= to_phy_driver(drv
);
71 struct net_device
*netdev
= phydev
->attached_dev
;
73 if (!drv
|| !phydrv
->suspend
)
76 /* PHY not attached? May suspend if the PHY has not already been
77 * suspended as part of a prior call to phy_disconnect() ->
78 * phy_detach() -> phy_suspend() because the parent netdev might be the
79 * MDIO bus driver and clock gated at this point.
82 return !phydev
->suspended
;
84 /* Don't suspend PHY if the attached netdev parent may wakeup.
85 * The parent may point to a PCI device, as in tg3 driver.
87 if (netdev
->dev
.parent
&& device_may_wakeup(netdev
->dev
.parent
))
90 /* Also don't suspend PHY if the netdev itself may wakeup. This
91 * is the case for devices w/o underlaying pwr. mgmt. aware bus,
94 if (device_may_wakeup(&netdev
->dev
))
100 static int mdio_bus_phy_suspend(struct device
*dev
)
102 struct phy_device
*phydev
= to_phy_device(dev
);
104 /* We must stop the state machine manually, otherwise it stops out of
105 * control, possibly with the phydev->lock held. Upon resume, netdev
106 * may call phy routines that try to grab the same lock, and that may
107 * lead to a deadlock.
109 if (phydev
->attached_dev
&& phydev
->adjust_link
)
110 phy_stop_machine(phydev
);
112 if (!mdio_bus_phy_may_suspend(phydev
))
115 return phy_suspend(phydev
);
118 static int mdio_bus_phy_resume(struct device
*dev
)
120 struct phy_device
*phydev
= to_phy_device(dev
);
123 if (!mdio_bus_phy_may_suspend(phydev
))
126 ret
= phy_resume(phydev
);
131 if (phydev
->attached_dev
&& phydev
->adjust_link
)
132 phy_start_machine(phydev
);
137 static int mdio_bus_phy_restore(struct device
*dev
)
139 struct phy_device
*phydev
= to_phy_device(dev
);
140 struct net_device
*netdev
= phydev
->attached_dev
;
146 ret
= phy_init_hw(phydev
);
150 /* The PHY needs to renegotiate. */
152 phydev
->state
= PHY_UP
;
154 phy_start_machine(phydev
);
159 static const struct dev_pm_ops mdio_bus_phy_pm_ops
= {
160 .suspend
= mdio_bus_phy_suspend
,
161 .resume
= mdio_bus_phy_resume
,
162 .freeze
= mdio_bus_phy_suspend
,
163 .thaw
= mdio_bus_phy_resume
,
164 .restore
= mdio_bus_phy_restore
,
167 #define MDIO_BUS_PHY_PM_OPS (&mdio_bus_phy_pm_ops)
171 #define MDIO_BUS_PHY_PM_OPS NULL
173 #endif /* CONFIG_PM */
176 * phy_register_fixup - creates a new phy_fixup and adds it to the list
177 * @bus_id: A string which matches phydev->mdio.dev.bus_id (or PHY_ANY_ID)
178 * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY)
179 * It can also be PHY_ANY_UID
180 * @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before
182 * @run: The actual code to be run when a matching PHY is found
184 int phy_register_fixup(const char *bus_id
, u32 phy_uid
, u32 phy_uid_mask
,
185 int (*run
)(struct phy_device
*))
187 struct phy_fixup
*fixup
= kzalloc(sizeof(*fixup
), GFP_KERNEL
);
192 strlcpy(fixup
->bus_id
, bus_id
, sizeof(fixup
->bus_id
));
193 fixup
->phy_uid
= phy_uid
;
194 fixup
->phy_uid_mask
= phy_uid_mask
;
197 mutex_lock(&phy_fixup_lock
);
198 list_add_tail(&fixup
->list
, &phy_fixup_list
);
199 mutex_unlock(&phy_fixup_lock
);
203 EXPORT_SYMBOL(phy_register_fixup
);
205 /* Registers a fixup to be run on any PHY with the UID in phy_uid */
206 int phy_register_fixup_for_uid(u32 phy_uid
, u32 phy_uid_mask
,
207 int (*run
)(struct phy_device
*))
209 return phy_register_fixup(PHY_ANY_ID
, phy_uid
, phy_uid_mask
, run
);
211 EXPORT_SYMBOL(phy_register_fixup_for_uid
);
213 /* Registers a fixup to be run on the PHY with id string bus_id */
214 int phy_register_fixup_for_id(const char *bus_id
,
215 int (*run
)(struct phy_device
*))
217 return phy_register_fixup(bus_id
, PHY_ANY_UID
, 0xffffffff, run
);
219 EXPORT_SYMBOL(phy_register_fixup_for_id
);
221 /* Returns 1 if fixup matches phydev in bus_id and phy_uid.
222 * Fixups can be set to match any in one or more fields.
224 static int phy_needs_fixup(struct phy_device
*phydev
, struct phy_fixup
*fixup
)
226 if (strcmp(fixup
->bus_id
, phydev_name(phydev
)) != 0)
227 if (strcmp(fixup
->bus_id
, PHY_ANY_ID
) != 0)
230 if ((fixup
->phy_uid
& fixup
->phy_uid_mask
) !=
231 (phydev
->phy_id
& fixup
->phy_uid_mask
))
232 if (fixup
->phy_uid
!= PHY_ANY_UID
)
238 /* Runs any matching fixups for this phydev */
239 static int phy_scan_fixups(struct phy_device
*phydev
)
241 struct phy_fixup
*fixup
;
243 mutex_lock(&phy_fixup_lock
);
244 list_for_each_entry(fixup
, &phy_fixup_list
, list
) {
245 if (phy_needs_fixup(phydev
, fixup
)) {
246 int err
= fixup
->run(phydev
);
249 mutex_unlock(&phy_fixup_lock
);
252 phydev
->has_fixups
= true;
255 mutex_unlock(&phy_fixup_lock
);
260 static int phy_bus_match(struct device
*dev
, struct device_driver
*drv
)
262 struct phy_device
*phydev
= to_phy_device(dev
);
263 struct phy_driver
*phydrv
= to_phy_driver(drv
);
264 const int num_ids
= ARRAY_SIZE(phydev
->c45_ids
.device_ids
);
267 if (!(phydrv
->mdiodrv
.flags
& MDIO_DEVICE_IS_PHY
))
270 if (phydrv
->match_phy_device
)
271 return phydrv
->match_phy_device(phydev
);
273 if (phydev
->is_c45
) {
274 for (i
= 1; i
< num_ids
; i
++) {
275 if (!(phydev
->c45_ids
.devices_in_package
& (1 << i
)))
278 if ((phydrv
->phy_id
& phydrv
->phy_id_mask
) ==
279 (phydev
->c45_ids
.device_ids
[i
] &
280 phydrv
->phy_id_mask
))
285 return (phydrv
->phy_id
& phydrv
->phy_id_mask
) ==
286 (phydev
->phy_id
& phydrv
->phy_id_mask
);
290 struct phy_device
*phy_device_create(struct mii_bus
*bus
, int addr
, int phy_id
,
292 struct phy_c45_device_ids
*c45_ids
)
294 struct phy_device
*dev
;
295 struct mdio_device
*mdiodev
;
297 /* We allocate the device, and initialize the default values */
298 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
300 return ERR_PTR(-ENOMEM
);
302 mdiodev
= &dev
->mdio
;
303 mdiodev
->dev
.release
= phy_device_release
;
304 mdiodev
->dev
.parent
= &bus
->dev
;
305 mdiodev
->dev
.bus
= &mdio_bus_type
;
307 mdiodev
->pm_ops
= MDIO_BUS_PHY_PM_OPS
;
308 mdiodev
->bus_match
= phy_bus_match
;
309 mdiodev
->addr
= addr
;
310 mdiodev
->flags
= MDIO_DEVICE_FLAG_PHY
;
317 dev
->interface
= PHY_INTERFACE_MODE_GMII
;
319 dev
->autoneg
= AUTONEG_ENABLE
;
321 dev
->is_c45
= is_c45
;
322 dev
->phy_id
= phy_id
;
324 dev
->c45_ids
= *c45_ids
;
325 dev
->irq
= bus
->irq
? bus
->irq
[addr
] : PHY_POLL
;
326 dev_set_name(&mdiodev
->dev
, PHY_ID_FMT
, bus
->id
, addr
);
328 dev
->state
= PHY_DOWN
;
330 mutex_init(&dev
->lock
);
331 INIT_DELAYED_WORK(&dev
->state_queue
, phy_state_machine
);
332 INIT_WORK(&dev
->phy_queue
, phy_change
);
334 /* Request the appropriate module unconditionally; don't
335 * bother trying to do so only if it isn't already loaded,
336 * because that gets complicated. A hotplug event would have
337 * done an unconditional modprobe anyway.
338 * We don't do normal hotplug because it won't work for MDIO
339 * -- because it relies on the device staying around for long
340 * enough for the driver to get loaded. With MDIO, the NIC
341 * driver will get bored and give up as soon as it finds that
342 * there's no driver _already_ loaded.
344 request_module(MDIO_MODULE_PREFIX MDIO_ID_FMT
, MDIO_ID_ARGS(phy_id
));
346 device_initialize(&mdiodev
->dev
);
350 EXPORT_SYMBOL(phy_device_create
);
352 /* get_phy_c45_devs_in_pkg - reads a MMD's devices in package registers.
353 * @bus: the target MII bus
354 * @addr: PHY address on the MII bus
355 * @dev_addr: MMD address in the PHY.
356 * @devices_in_package: where to store the devices in package information.
358 * Description: reads devices in package registers of a MMD at @dev_addr
359 * from PHY at @addr on @bus.
361 * Returns: 0 on success, -EIO on failure.
363 static int get_phy_c45_devs_in_pkg(struct mii_bus
*bus
, int addr
, int dev_addr
,
364 u32
*devices_in_package
)
366 int phy_reg
, reg_addr
;
368 reg_addr
= MII_ADDR_C45
| dev_addr
<< 16 | MDIO_DEVS2
;
369 phy_reg
= mdiobus_read(bus
, addr
, reg_addr
);
372 *devices_in_package
= (phy_reg
& 0xffff) << 16;
374 reg_addr
= MII_ADDR_C45
| dev_addr
<< 16 | MDIO_DEVS1
;
375 phy_reg
= mdiobus_read(bus
, addr
, reg_addr
);
378 *devices_in_package
|= (phy_reg
& 0xffff);
384 * get_phy_c45_ids - reads the specified addr for its 802.3-c45 IDs.
385 * @bus: the target MII bus
386 * @addr: PHY address on the MII bus
387 * @phy_id: where to store the ID retrieved.
388 * @c45_ids: where to store the c45 ID information.
390 * If the PHY devices-in-package appears to be valid, it and the
391 * corresponding identifiers are stored in @c45_ids, zero is stored
392 * in @phy_id. Otherwise 0xffffffff is stored in @phy_id. Returns
396 static int get_phy_c45_ids(struct mii_bus
*bus
, int addr
, u32
*phy_id
,
397 struct phy_c45_device_ids
*c45_ids
) {
400 const int num_ids
= ARRAY_SIZE(c45_ids
->device_ids
);
401 u32
*devs
= &c45_ids
->devices_in_package
;
403 /* Find first non-zero Devices In package. Device zero is reserved
404 * for 802.3 c45 complied PHYs, so don't probe it at first.
406 for (i
= 1; i
< num_ids
&& *devs
== 0; i
++) {
407 phy_reg
= get_phy_c45_devs_in_pkg(bus
, addr
, i
, devs
);
411 if ((*devs
& 0x1fffffff) == 0x1fffffff) {
412 /* If mostly Fs, there is no device there,
413 * then let's continue to probe more, as some
414 * 10G PHYs have zero Devices In package,
415 * e.g. Cortina CS4315/CS4340 PHY.
417 phy_reg
= get_phy_c45_devs_in_pkg(bus
, addr
, 0, devs
);
420 /* no device there, let's get out of here */
421 if ((*devs
& 0x1fffffff) == 0x1fffffff) {
422 *phy_id
= 0xffffffff;
430 /* Now probe Device Identifiers for each device present. */
431 for (i
= 1; i
< num_ids
; i
++) {
432 if (!(c45_ids
->devices_in_package
& (1 << i
)))
435 reg_addr
= MII_ADDR_C45
| i
<< 16 | MII_PHYSID1
;
436 phy_reg
= mdiobus_read(bus
, addr
, reg_addr
);
439 c45_ids
->device_ids
[i
] = (phy_reg
& 0xffff) << 16;
441 reg_addr
= MII_ADDR_C45
| i
<< 16 | MII_PHYSID2
;
442 phy_reg
= mdiobus_read(bus
, addr
, reg_addr
);
445 c45_ids
->device_ids
[i
] |= (phy_reg
& 0xffff);
452 * get_phy_id - reads the specified addr for its ID.
453 * @bus: the target MII bus
454 * @addr: PHY address on the MII bus
455 * @phy_id: where to store the ID retrieved.
456 * @is_c45: If true the PHY uses the 802.3 clause 45 protocol
457 * @c45_ids: where to store the c45 ID information.
459 * Description: In the case of a 802.3-c22 PHY, reads the ID registers
460 * of the PHY at @addr on the @bus, stores it in @phy_id and returns
463 * In the case of a 802.3-c45 PHY, get_phy_c45_ids() is invoked, and
464 * its return value is in turn returned.
467 static int get_phy_id(struct mii_bus
*bus
, int addr
, u32
*phy_id
,
468 bool is_c45
, struct phy_c45_device_ids
*c45_ids
)
473 return get_phy_c45_ids(bus
, addr
, phy_id
, c45_ids
);
475 /* Grab the bits from PHYIR1, and put them in the upper half */
476 phy_reg
= mdiobus_read(bus
, addr
, MII_PHYSID1
);
480 *phy_id
= (phy_reg
& 0xffff) << 16;
482 /* Grab the bits from PHYIR2, and put them in the lower half */
483 phy_reg
= mdiobus_read(bus
, addr
, MII_PHYSID2
);
487 *phy_id
|= (phy_reg
& 0xffff);
493 * get_phy_device - reads the specified PHY device and returns its @phy_device
495 * @bus: the target MII bus
496 * @addr: PHY address on the MII bus
497 * @is_c45: If true the PHY uses the 802.3 clause 45 protocol
499 * Description: Reads the ID registers of the PHY at @addr on the
500 * @bus, then allocates and returns the phy_device to represent it.
502 struct phy_device
*get_phy_device(struct mii_bus
*bus
, int addr
, bool is_c45
)
504 struct phy_c45_device_ids c45_ids
= {0};
508 r
= get_phy_id(bus
, addr
, &phy_id
, is_c45
, &c45_ids
);
512 /* If the phy_id is mostly Fs, there is no device there */
513 if ((phy_id
& 0x1fffffff) == 0x1fffffff)
516 return phy_device_create(bus
, addr
, phy_id
, is_c45
, &c45_ids
);
518 EXPORT_SYMBOL(get_phy_device
);
521 phy_id_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
523 struct phy_device
*phydev
= to_phy_device(dev
);
525 return sprintf(buf
, "0x%.8lx\n", (unsigned long)phydev
->phy_id
);
527 static DEVICE_ATTR_RO(phy_id
);
530 phy_interface_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
532 struct phy_device
*phydev
= to_phy_device(dev
);
533 const char *mode
= NULL
;
535 if (phy_is_internal(phydev
))
538 mode
= phy_modes(phydev
->interface
);
540 return sprintf(buf
, "%s\n", mode
);
542 static DEVICE_ATTR_RO(phy_interface
);
545 phy_has_fixups_show(struct device
*dev
, struct device_attribute
*attr
,
548 struct phy_device
*phydev
= to_phy_device(dev
);
550 return sprintf(buf
, "%d\n", phydev
->has_fixups
);
552 static DEVICE_ATTR_RO(phy_has_fixups
);
554 static struct attribute
*phy_dev_attrs
[] = {
555 &dev_attr_phy_id
.attr
,
556 &dev_attr_phy_interface
.attr
,
557 &dev_attr_phy_has_fixups
.attr
,
560 ATTRIBUTE_GROUPS(phy_dev
);
563 * phy_device_register - Register the phy device on the MDIO bus
564 * @phydev: phy_device structure to be added to the MDIO bus
566 int phy_device_register(struct phy_device
*phydev
)
570 err
= mdiobus_register_device(&phydev
->mdio
);
574 /* Run all of the fixups for this PHY */
575 err
= phy_scan_fixups(phydev
);
577 pr_err("PHY %d failed to initialize\n", phydev
->mdio
.addr
);
581 phydev
->mdio
.dev
.groups
= phy_dev_groups
;
583 err
= device_add(&phydev
->mdio
.dev
);
585 pr_err("PHY %d failed to add\n", phydev
->mdio
.addr
);
592 mdiobus_unregister_device(&phydev
->mdio
);
595 EXPORT_SYMBOL(phy_device_register
);
598 * phy_device_remove - Remove a previously registered phy device from the MDIO bus
599 * @phydev: phy_device structure to remove
601 * This doesn't free the phy_device itself, it merely reverses the effects
602 * of phy_device_register(). Use phy_device_free() to free the device
603 * after calling this function.
605 void phy_device_remove(struct phy_device
*phydev
)
607 device_del(&phydev
->mdio
.dev
);
608 mdiobus_unregister_device(&phydev
->mdio
);
610 EXPORT_SYMBOL(phy_device_remove
);
613 * phy_find_first - finds the first PHY device on the bus
614 * @bus: the target MII bus
616 struct phy_device
*phy_find_first(struct mii_bus
*bus
)
618 struct phy_device
*phydev
;
621 for (addr
= 0; addr
< PHY_MAX_ADDR
; addr
++) {
622 phydev
= mdiobus_get_phy(bus
, addr
);
628 EXPORT_SYMBOL(phy_find_first
);
631 * phy_prepare_link - prepares the PHY layer to monitor link status
632 * @phydev: target phy_device struct
633 * @handler: callback function for link status change notifications
635 * Description: Tells the PHY infrastructure to handle the
636 * gory details on monitoring link status (whether through
637 * polling or an interrupt), and to call back to the
638 * connected device driver when the link status changes.
639 * If you want to monitor your own link state, don't call
642 static void phy_prepare_link(struct phy_device
*phydev
,
643 void (*handler
)(struct net_device
*))
645 phydev
->adjust_link
= handler
;
649 * phy_connect_direct - connect an ethernet device to a specific phy_device
650 * @dev: the network device to connect
651 * @phydev: the pointer to the phy device
652 * @handler: callback function for state change notifications
653 * @interface: PHY device's interface
655 int phy_connect_direct(struct net_device
*dev
, struct phy_device
*phydev
,
656 void (*handler
)(struct net_device
*),
657 phy_interface_t interface
)
661 rc
= phy_attach_direct(dev
, phydev
, phydev
->dev_flags
, interface
);
665 phy_prepare_link(phydev
, handler
);
666 phy_start_machine(phydev
);
668 phy_start_interrupts(phydev
);
672 EXPORT_SYMBOL(phy_connect_direct
);
675 * phy_connect - connect an ethernet device to a PHY device
676 * @dev: the network device to connect
677 * @bus_id: the id string of the PHY device to connect
678 * @handler: callback function for state change notifications
679 * @interface: PHY device's interface
681 * Description: Convenience function for connecting ethernet
682 * devices to PHY devices. The default behavior is for
683 * the PHY infrastructure to handle everything, and only notify
684 * the connected driver when the link status changes. If you
685 * don't want, or can't use the provided functionality, you may
686 * choose to call only the subset of functions which provide
687 * the desired functionality.
689 struct phy_device
*phy_connect(struct net_device
*dev
, const char *bus_id
,
690 void (*handler
)(struct net_device
*),
691 phy_interface_t interface
)
693 struct phy_device
*phydev
;
697 /* Search the list of PHY devices on the mdio bus for the
698 * PHY with the requested name
700 d
= bus_find_device_by_name(&mdio_bus_type
, NULL
, bus_id
);
702 pr_err("PHY %s not found\n", bus_id
);
703 return ERR_PTR(-ENODEV
);
705 phydev
= to_phy_device(d
);
707 rc
= phy_connect_direct(dev
, phydev
, handler
, interface
);
713 EXPORT_SYMBOL(phy_connect
);
716 * phy_disconnect - disable interrupts, stop state machine, and detach a PHY
718 * @phydev: target phy_device struct
720 void phy_disconnect(struct phy_device
*phydev
)
723 phy_stop_interrupts(phydev
);
725 phy_stop_machine(phydev
);
727 phydev
->adjust_link
= NULL
;
731 EXPORT_SYMBOL(phy_disconnect
);
734 * phy_poll_reset - Safely wait until a PHY reset has properly completed
735 * @phydev: The PHY device to poll
737 * Description: According to IEEE 802.3, Section 2, Subsection 22.2.4.1.1, as
738 * published in 2008, a PHY reset may take up to 0.5 seconds. The MII BMCR
739 * register must be polled until the BMCR_RESET bit clears.
741 * Furthermore, any attempts to write to PHY registers may have no effect
742 * or even generate MDIO bus errors until this is complete.
744 * Some PHYs (such as the Marvell 88E1111) don't entirely conform to the
745 * standard and do not fully reset after the BMCR_RESET bit is set, and may
746 * even *REQUIRE* a soft-reset to properly restart autonegotiation. In an
747 * effort to support such broken PHYs, this function is separate from the
748 * standard phy_init_hw() which will zero all the other bits in the BMCR
749 * and reapply all driver-specific and board-specific fixups.
751 static int phy_poll_reset(struct phy_device
*phydev
)
753 /* Poll until the reset bit clears (50ms per retry == 0.6 sec) */
754 unsigned int retries
= 12;
759 ret
= phy_read(phydev
, MII_BMCR
);
762 } while (ret
& BMCR_RESET
&& --retries
);
763 if (ret
& BMCR_RESET
)
766 /* Some chips (smsc911x) may still need up to another 1ms after the
767 * BMCR_RESET bit is cleared before they are usable.
773 int phy_init_hw(struct phy_device
*phydev
)
777 if (!phydev
->drv
|| !phydev
->drv
->config_init
)
780 if (phydev
->drv
->soft_reset
)
781 ret
= phydev
->drv
->soft_reset(phydev
);
783 ret
= genphy_soft_reset(phydev
);
788 ret
= phy_scan_fixups(phydev
);
792 return phydev
->drv
->config_init(phydev
);
794 EXPORT_SYMBOL(phy_init_hw
);
796 void phy_attached_info(struct phy_device
*phydev
)
798 phy_attached_print(phydev
, NULL
);
800 EXPORT_SYMBOL(phy_attached_info
);
802 #define ATTACHED_FMT "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)"
803 void phy_attached_print(struct phy_device
*phydev
, const char *fmt
, ...)
806 dev_info(&phydev
->mdio
.dev
, ATTACHED_FMT
"\n",
807 phydev
->drv
->name
, phydev_name(phydev
),
812 dev_info(&phydev
->mdio
.dev
, ATTACHED_FMT
,
813 phydev
->drv
->name
, phydev_name(phydev
),
821 EXPORT_SYMBOL(phy_attached_print
);
824 * phy_attach_direct - attach a network device to a given PHY device pointer
825 * @dev: network device to attach
826 * @phydev: Pointer to phy_device to attach
827 * @flags: PHY device's dev_flags
828 * @interface: PHY device's interface
830 * Description: Called by drivers to attach to a particular PHY
831 * device. The phy_device is found, and properly hooked up
832 * to the phy_driver. If no driver is attached, then a
833 * generic driver is used. The phy_device is given a ptr to
834 * the attaching device, and given a callback for link status
835 * change. The phy_device is returned to the attaching driver.
836 * This function takes a reference on the phy device.
838 int phy_attach_direct(struct net_device
*dev
, struct phy_device
*phydev
,
839 u32 flags
, phy_interface_t interface
)
841 struct mii_bus
*bus
= phydev
->mdio
.bus
;
842 struct device
*d
= &phydev
->mdio
.dev
;
845 if (!try_module_get(bus
->owner
)) {
846 dev_err(&dev
->dev
, "failed to get the bus module\n");
852 /* Assume that if there is no driver, that it doesn't
853 * exist, and we should use the genphy driver.
858 &genphy_driver
[GENPHY_DRV_10G
].mdiodrv
.driver
;
861 &genphy_driver
[GENPHY_DRV_1G
].mdiodrv
.driver
;
863 err
= d
->driver
->probe(d
);
865 err
= device_bind_driver(d
);
871 if (phydev
->attached_dev
) {
872 dev_err(&dev
->dev
, "PHY already attached\n");
877 phydev
->attached_dev
= dev
;
878 dev
->phydev
= phydev
;
880 phydev
->dev_flags
= flags
;
882 phydev
->interface
= interface
;
884 phydev
->state
= PHY_READY
;
886 /* Do initial configuration here, now that
887 * we have certain key parameters
888 * (dev_flags and interface)
890 err
= phy_init_hw(phydev
);
900 module_put(bus
->owner
);
903 EXPORT_SYMBOL(phy_attach_direct
);
906 * phy_attach - attach a network device to a particular PHY device
907 * @dev: network device to attach
908 * @bus_id: Bus ID of PHY device to attach
909 * @interface: PHY device's interface
911 * Description: Same as phy_attach_direct() except that a PHY bus_id
912 * string is passed instead of a pointer to a struct phy_device.
914 struct phy_device
*phy_attach(struct net_device
*dev
, const char *bus_id
,
915 phy_interface_t interface
)
917 struct bus_type
*bus
= &mdio_bus_type
;
918 struct phy_device
*phydev
;
922 /* Search the list of PHY devices on the mdio bus for the
923 * PHY with the requested name
925 d
= bus_find_device_by_name(bus
, NULL
, bus_id
);
927 pr_err("PHY %s not found\n", bus_id
);
928 return ERR_PTR(-ENODEV
);
930 phydev
= to_phy_device(d
);
932 rc
= phy_attach_direct(dev
, phydev
, phydev
->dev_flags
, interface
);
938 EXPORT_SYMBOL(phy_attach
);
941 * phy_detach - detach a PHY device from its network device
942 * @phydev: target phy_device struct
944 * This detaches the phy device from its network device and the phy
945 * driver, and drops the reference count taken in phy_attach_direct().
947 void phy_detach(struct phy_device
*phydev
)
952 phydev
->attached_dev
->phydev
= NULL
;
953 phydev
->attached_dev
= NULL
;
956 /* If the device had no specific driver before (i.e. - it
957 * was using the generic driver), we unbind the device
958 * from the generic driver so that there's a chance a
959 * real driver could be loaded
961 for (i
= 0; i
< ARRAY_SIZE(genphy_driver
); i
++) {
962 if (phydev
->mdio
.dev
.driver
==
963 &genphy_driver
[i
].mdiodrv
.driver
) {
964 device_release_driver(&phydev
->mdio
.dev
);
970 * The phydev might go away on the put_device() below, so avoid
971 * a use-after-free bug by reading the underlying bus first.
973 bus
= phydev
->mdio
.bus
;
975 put_device(&phydev
->mdio
.dev
);
976 module_put(bus
->owner
);
978 EXPORT_SYMBOL(phy_detach
);
980 int phy_suspend(struct phy_device
*phydev
)
982 struct phy_driver
*phydrv
= to_phy_driver(phydev
->mdio
.dev
.driver
);
983 struct ethtool_wolinfo wol
= { .cmd
= ETHTOOL_GWOL
};
986 /* If the device has WOL enabled, we cannot suspend the PHY */
987 phy_ethtool_get_wol(phydev
, &wol
);
992 ret
= phydrv
->suspend(phydev
);
997 phydev
->suspended
= true;
1001 EXPORT_SYMBOL(phy_suspend
);
1003 int phy_resume(struct phy_device
*phydev
)
1005 struct phy_driver
*phydrv
= to_phy_driver(phydev
->mdio
.dev
.driver
);
1009 ret
= phydrv
->resume(phydev
);
1014 phydev
->suspended
= false;
1018 EXPORT_SYMBOL(phy_resume
);
1020 /* Generic PHY support and helper functions */
1023 * genphy_config_advert - sanitize and advertise auto-negotiation parameters
1024 * @phydev: target phy_device struct
1026 * Description: Writes MII_ADVERTISE with the appropriate values,
1027 * after sanitizing the values to make sure we only advertise
1028 * what is supported. Returns < 0 on error, 0 if the PHY's advertisement
1029 * hasn't changed, and > 0 if it has changed.
1031 static int genphy_config_advert(struct phy_device
*phydev
)
1034 int oldadv
, adv
, bmsr
;
1035 int err
, changed
= 0;
1037 /* Only allow advertising what this PHY supports */
1038 phydev
->advertising
&= phydev
->supported
;
1039 advertise
= phydev
->advertising
;
1041 /* Setup standard advertisement */
1042 adv
= phy_read(phydev
, MII_ADVERTISE
);
1047 adv
&= ~(ADVERTISE_ALL
| ADVERTISE_100BASE4
| ADVERTISE_PAUSE_CAP
|
1048 ADVERTISE_PAUSE_ASYM
);
1049 adv
|= ethtool_adv_to_mii_adv_t(advertise
);
1051 if (adv
!= oldadv
) {
1052 err
= phy_write(phydev
, MII_ADVERTISE
, adv
);
1059 bmsr
= phy_read(phydev
, MII_BMSR
);
1063 /* Per 802.3-2008, Section 22.2.4.2.16 Extended status all
1064 * 1000Mbits/sec capable PHYs shall have the BMSR_ESTATEN bit set to a
1067 if (!(bmsr
& BMSR_ESTATEN
))
1070 /* Configure gigabit if it's supported */
1071 adv
= phy_read(phydev
, MII_CTRL1000
);
1076 adv
&= ~(ADVERTISE_1000FULL
| ADVERTISE_1000HALF
);
1078 if (phydev
->supported
& (SUPPORTED_1000baseT_Half
|
1079 SUPPORTED_1000baseT_Full
)) {
1080 adv
|= ethtool_adv_to_mii_ctrl1000_t(advertise
);
1086 err
= phy_write(phydev
, MII_CTRL1000
, adv
);
1094 * genphy_setup_forced - configures/forces speed/duplex from @phydev
1095 * @phydev: target phy_device struct
1097 * Description: Configures MII_BMCR to force speed/duplex
1098 * to the values in phydev. Assumes that the values are valid.
1099 * Please see phy_sanitize_settings().
1101 int genphy_setup_forced(struct phy_device
*phydev
)
1106 phydev
->asym_pause
= 0;
1108 if (SPEED_1000
== phydev
->speed
)
1109 ctl
|= BMCR_SPEED1000
;
1110 else if (SPEED_100
== phydev
->speed
)
1111 ctl
|= BMCR_SPEED100
;
1113 if (DUPLEX_FULL
== phydev
->duplex
)
1114 ctl
|= BMCR_FULLDPLX
;
1116 return phy_write(phydev
, MII_BMCR
, ctl
);
1118 EXPORT_SYMBOL(genphy_setup_forced
);
1121 * genphy_restart_aneg - Enable and Restart Autonegotiation
1122 * @phydev: target phy_device struct
1124 int genphy_restart_aneg(struct phy_device
*phydev
)
1126 int ctl
= phy_read(phydev
, MII_BMCR
);
1131 ctl
|= BMCR_ANENABLE
| BMCR_ANRESTART
;
1133 /* Don't isolate the PHY if we're negotiating */
1134 ctl
&= ~BMCR_ISOLATE
;
1136 return phy_write(phydev
, MII_BMCR
, ctl
);
1138 EXPORT_SYMBOL(genphy_restart_aneg
);
1141 * genphy_config_aneg - restart auto-negotiation or write BMCR
1142 * @phydev: target phy_device struct
1144 * Description: If auto-negotiation is enabled, we configure the
1145 * advertising, and then restart auto-negotiation. If it is not
1146 * enabled, then we write the BMCR.
1148 int genphy_config_aneg(struct phy_device
*phydev
)
1152 if (AUTONEG_ENABLE
!= phydev
->autoneg
)
1153 return genphy_setup_forced(phydev
);
1155 result
= genphy_config_advert(phydev
);
1156 if (result
< 0) /* error */
1159 /* Advertisement hasn't changed, but maybe aneg was never on to
1160 * begin with? Or maybe phy was isolated?
1162 int ctl
= phy_read(phydev
, MII_BMCR
);
1167 if (!(ctl
& BMCR_ANENABLE
) || (ctl
& BMCR_ISOLATE
))
1168 result
= 1; /* do restart aneg */
1171 /* Only restart aneg if we are advertising something different
1172 * than we were before.
1175 result
= genphy_restart_aneg(phydev
);
1179 EXPORT_SYMBOL(genphy_config_aneg
);
1182 * genphy_aneg_done - return auto-negotiation status
1183 * @phydev: target phy_device struct
1185 * Description: Reads the status register and returns 0 either if
1186 * auto-negotiation is incomplete, or if there was an error.
1187 * Returns BMSR_ANEGCOMPLETE if auto-negotiation is done.
1189 int genphy_aneg_done(struct phy_device
*phydev
)
1191 int retval
= phy_read(phydev
, MII_BMSR
);
1193 return (retval
< 0) ? retval
: (retval
& BMSR_ANEGCOMPLETE
);
1195 EXPORT_SYMBOL(genphy_aneg_done
);
1197 static int gen10g_config_aneg(struct phy_device
*phydev
)
1203 * genphy_update_link - update link status in @phydev
1204 * @phydev: target phy_device struct
1206 * Description: Update the value in phydev->link to reflect the
1207 * current link value. In order to do this, we need to read
1208 * the status register twice, keeping the second value.
1210 int genphy_update_link(struct phy_device
*phydev
)
1214 /* Do a fake read */
1215 status
= phy_read(phydev
, MII_BMSR
);
1219 /* Read link and autonegotiation status */
1220 status
= phy_read(phydev
, MII_BMSR
);
1224 if ((status
& BMSR_LSTATUS
) == 0)
1231 EXPORT_SYMBOL(genphy_update_link
);
1234 * genphy_read_status - check the link status and update current link state
1235 * @phydev: target phy_device struct
1237 * Description: Check the link, then figure out the current state
1238 * by comparing what we advertise with what the link partner
1239 * advertises. Start by checking the gigabit possibilities,
1240 * then move on to 10/100.
1242 int genphy_read_status(struct phy_device
*phydev
)
1249 int common_adv_gb
= 0;
1251 /* Update the link, but return if there was an error */
1252 err
= genphy_update_link(phydev
);
1256 phydev
->lp_advertising
= 0;
1258 if (AUTONEG_ENABLE
== phydev
->autoneg
) {
1259 if (phydev
->supported
& (SUPPORTED_1000baseT_Half
1260 | SUPPORTED_1000baseT_Full
)) {
1261 lpagb
= phy_read(phydev
, MII_STAT1000
);
1265 adv
= phy_read(phydev
, MII_CTRL1000
);
1269 phydev
->lp_advertising
=
1270 mii_stat1000_to_ethtool_lpa_t(lpagb
);
1271 common_adv_gb
= lpagb
& adv
<< 2;
1274 lpa
= phy_read(phydev
, MII_LPA
);
1278 phydev
->lp_advertising
|= mii_lpa_to_ethtool_lpa_t(lpa
);
1280 adv
= phy_read(phydev
, MII_ADVERTISE
);
1284 common_adv
= lpa
& adv
;
1286 phydev
->speed
= SPEED_10
;
1287 phydev
->duplex
= DUPLEX_HALF
;
1289 phydev
->asym_pause
= 0;
1291 if (common_adv_gb
& (LPA_1000FULL
| LPA_1000HALF
)) {
1292 phydev
->speed
= SPEED_1000
;
1294 if (common_adv_gb
& LPA_1000FULL
)
1295 phydev
->duplex
= DUPLEX_FULL
;
1296 } else if (common_adv
& (LPA_100FULL
| LPA_100HALF
)) {
1297 phydev
->speed
= SPEED_100
;
1299 if (common_adv
& LPA_100FULL
)
1300 phydev
->duplex
= DUPLEX_FULL
;
1302 if (common_adv
& LPA_10FULL
)
1303 phydev
->duplex
= DUPLEX_FULL
;
1305 if (phydev
->duplex
== DUPLEX_FULL
) {
1306 phydev
->pause
= lpa
& LPA_PAUSE_CAP
? 1 : 0;
1307 phydev
->asym_pause
= lpa
& LPA_PAUSE_ASYM
? 1 : 0;
1310 int bmcr
= phy_read(phydev
, MII_BMCR
);
1315 if (bmcr
& BMCR_FULLDPLX
)
1316 phydev
->duplex
= DUPLEX_FULL
;
1318 phydev
->duplex
= DUPLEX_HALF
;
1320 if (bmcr
& BMCR_SPEED1000
)
1321 phydev
->speed
= SPEED_1000
;
1322 else if (bmcr
& BMCR_SPEED100
)
1323 phydev
->speed
= SPEED_100
;
1325 phydev
->speed
= SPEED_10
;
1328 phydev
->asym_pause
= 0;
1333 EXPORT_SYMBOL(genphy_read_status
);
1335 static int gen10g_read_status(struct phy_device
*phydev
)
1338 u32 mmd_mask
= phydev
->c45_ids
.devices_in_package
;
1342 /* For now just lie and say it's 10G all the time */
1343 phydev
->speed
= SPEED_10000
;
1344 phydev
->duplex
= DUPLEX_FULL
;
1346 for (devad
= 0; mmd_mask
; devad
++, mmd_mask
= mmd_mask
>> 1) {
1347 if (!(mmd_mask
& 1))
1350 /* Read twice because link state is latched and a
1351 * read moves the current state into the register
1353 phy_read_mmd(phydev
, devad
, MDIO_STAT1
);
1354 reg
= phy_read_mmd(phydev
, devad
, MDIO_STAT1
);
1355 if (reg
< 0 || !(reg
& MDIO_STAT1_LSTATUS
))
1363 * genphy_soft_reset - software reset the PHY via BMCR_RESET bit
1364 * @phydev: target phy_device struct
1366 * Description: Perform a software PHY reset using the standard
1367 * BMCR_RESET bit and poll for the reset bit to be cleared.
1369 * Returns: 0 on success, < 0 on failure
1371 int genphy_soft_reset(struct phy_device
*phydev
)
1375 ret
= phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
1379 return phy_poll_reset(phydev
);
1381 EXPORT_SYMBOL(genphy_soft_reset
);
1383 int genphy_config_init(struct phy_device
*phydev
)
1388 features
= (SUPPORTED_TP
| SUPPORTED_MII
1389 | SUPPORTED_AUI
| SUPPORTED_FIBRE
|
1392 /* Do we support autonegotiation? */
1393 val
= phy_read(phydev
, MII_BMSR
);
1397 if (val
& BMSR_ANEGCAPABLE
)
1398 features
|= SUPPORTED_Autoneg
;
1400 if (val
& BMSR_100FULL
)
1401 features
|= SUPPORTED_100baseT_Full
;
1402 if (val
& BMSR_100HALF
)
1403 features
|= SUPPORTED_100baseT_Half
;
1404 if (val
& BMSR_10FULL
)
1405 features
|= SUPPORTED_10baseT_Full
;
1406 if (val
& BMSR_10HALF
)
1407 features
|= SUPPORTED_10baseT_Half
;
1409 if (val
& BMSR_ESTATEN
) {
1410 val
= phy_read(phydev
, MII_ESTATUS
);
1414 if (val
& ESTATUS_1000_TFULL
)
1415 features
|= SUPPORTED_1000baseT_Full
;
1416 if (val
& ESTATUS_1000_THALF
)
1417 features
|= SUPPORTED_1000baseT_Half
;
1420 phydev
->supported
&= features
;
1421 phydev
->advertising
&= features
;
1426 static int gen10g_soft_reset(struct phy_device
*phydev
)
1428 /* Do nothing for now */
1431 EXPORT_SYMBOL(genphy_config_init
);
1433 static int gen10g_config_init(struct phy_device
*phydev
)
1435 /* Temporarily just say we support everything */
1436 phydev
->supported
= SUPPORTED_10000baseT_Full
;
1437 phydev
->advertising
= SUPPORTED_10000baseT_Full
;
1442 int genphy_suspend(struct phy_device
*phydev
)
1446 mutex_lock(&phydev
->lock
);
1448 value
= phy_read(phydev
, MII_BMCR
);
1449 phy_write(phydev
, MII_BMCR
, value
| BMCR_PDOWN
);
1451 mutex_unlock(&phydev
->lock
);
1455 EXPORT_SYMBOL(genphy_suspend
);
1457 static int gen10g_suspend(struct phy_device
*phydev
)
1462 int genphy_resume(struct phy_device
*phydev
)
1466 mutex_lock(&phydev
->lock
);
1468 value
= phy_read(phydev
, MII_BMCR
);
1469 phy_write(phydev
, MII_BMCR
, value
& ~BMCR_PDOWN
);
1471 mutex_unlock(&phydev
->lock
);
1475 EXPORT_SYMBOL(genphy_resume
);
1477 static int gen10g_resume(struct phy_device
*phydev
)
1482 static int __set_phy_supported(struct phy_device
*phydev
, u32 max_speed
)
1484 /* The default values for phydev->supported are provided by the PHY
1485 * driver "features" member, we want to reset to sane defaults first
1486 * before supporting higher speeds.
1488 phydev
->supported
&= PHY_DEFAULT_FEATURES
;
1490 switch (max_speed
) {
1494 phydev
->supported
|= PHY_1000BT_FEATURES
;
1497 phydev
->supported
|= PHY_100BT_FEATURES
;
1500 phydev
->supported
|= PHY_10BT_FEATURES
;
1506 int phy_set_max_speed(struct phy_device
*phydev
, u32 max_speed
)
1510 err
= __set_phy_supported(phydev
, max_speed
);
1514 phydev
->advertising
= phydev
->supported
;
1518 EXPORT_SYMBOL(phy_set_max_speed
);
1520 static void of_set_phy_supported(struct phy_device
*phydev
)
1522 struct device_node
*node
= phydev
->mdio
.dev
.of_node
;
1525 if (!IS_ENABLED(CONFIG_OF_MDIO
))
1531 if (!of_property_read_u32(node
, "max-speed", &max_speed
))
1532 __set_phy_supported(phydev
, max_speed
);
1536 * phy_probe - probe and init a PHY device
1537 * @dev: device to probe and init
1539 * Description: Take care of setting up the phy_device structure,
1540 * set the state to READY (the driver's init function should
1541 * set it to STARTING if needed).
1543 static int phy_probe(struct device
*dev
)
1545 struct phy_device
*phydev
= to_phy_device(dev
);
1546 struct device_driver
*drv
= phydev
->mdio
.dev
.driver
;
1547 struct phy_driver
*phydrv
= to_phy_driver(drv
);
1550 phydev
->drv
= phydrv
;
1552 /* Disable the interrupt if the PHY doesn't support it
1553 * but the interrupt is still a valid one
1555 if (!(phydrv
->flags
& PHY_HAS_INTERRUPT
) &&
1556 phy_interrupt_is_valid(phydev
))
1557 phydev
->irq
= PHY_POLL
;
1559 if (phydrv
->flags
& PHY_IS_INTERNAL
)
1560 phydev
->is_internal
= true;
1562 mutex_lock(&phydev
->lock
);
1564 /* Start out supporting everything. Eventually,
1565 * a controller will attach, and may modify one
1566 * or both of these values
1568 phydev
->supported
= phydrv
->features
;
1569 of_set_phy_supported(phydev
);
1570 phydev
->advertising
= phydev
->supported
;
1572 /* Set the state to READY by default */
1573 phydev
->state
= PHY_READY
;
1575 if (phydev
->drv
->probe
)
1576 err
= phydev
->drv
->probe(phydev
);
1578 mutex_unlock(&phydev
->lock
);
1583 static int phy_remove(struct device
*dev
)
1585 struct phy_device
*phydev
= to_phy_device(dev
);
1587 mutex_lock(&phydev
->lock
);
1588 phydev
->state
= PHY_DOWN
;
1589 mutex_unlock(&phydev
->lock
);
1591 if (phydev
->drv
->remove
)
1592 phydev
->drv
->remove(phydev
);
1599 * phy_driver_register - register a phy_driver with the PHY layer
1600 * @new_driver: new phy_driver to register
1601 * @owner: module owning this PHY
1603 int phy_driver_register(struct phy_driver
*new_driver
, struct module
*owner
)
1607 new_driver
->mdiodrv
.flags
|= MDIO_DEVICE_IS_PHY
;
1608 new_driver
->mdiodrv
.driver
.name
= new_driver
->name
;
1609 new_driver
->mdiodrv
.driver
.bus
= &mdio_bus_type
;
1610 new_driver
->mdiodrv
.driver
.probe
= phy_probe
;
1611 new_driver
->mdiodrv
.driver
.remove
= phy_remove
;
1612 new_driver
->mdiodrv
.driver
.owner
= owner
;
1614 retval
= driver_register(&new_driver
->mdiodrv
.driver
);
1616 pr_err("%s: Error %d in registering driver\n",
1617 new_driver
->name
, retval
);
1622 pr_debug("%s: Registered new driver\n", new_driver
->name
);
1626 EXPORT_SYMBOL(phy_driver_register
);
1628 int phy_drivers_register(struct phy_driver
*new_driver
, int n
,
1629 struct module
*owner
)
1633 for (i
= 0; i
< n
; i
++) {
1634 ret
= phy_driver_register(new_driver
+ i
, owner
);
1637 phy_driver_unregister(new_driver
+ i
);
1643 EXPORT_SYMBOL(phy_drivers_register
);
1645 void phy_driver_unregister(struct phy_driver
*drv
)
1647 driver_unregister(&drv
->mdiodrv
.driver
);
1649 EXPORT_SYMBOL(phy_driver_unregister
);
1651 void phy_drivers_unregister(struct phy_driver
*drv
, int n
)
1655 for (i
= 0; i
< n
; i
++)
1656 phy_driver_unregister(drv
+ i
);
1658 EXPORT_SYMBOL(phy_drivers_unregister
);
1660 static struct phy_driver genphy_driver
[] = {
1662 .phy_id
= 0xffffffff,
1663 .phy_id_mask
= 0xffffffff,
1664 .name
= "Generic PHY",
1665 .soft_reset
= genphy_soft_reset
,
1666 .config_init
= genphy_config_init
,
1667 .features
= PHY_GBIT_FEATURES
| SUPPORTED_MII
|
1668 SUPPORTED_AUI
| SUPPORTED_FIBRE
|
1670 .config_aneg
= genphy_config_aneg
,
1671 .aneg_done
= genphy_aneg_done
,
1672 .read_status
= genphy_read_status
,
1673 .suspend
= genphy_suspend
,
1674 .resume
= genphy_resume
,
1676 .phy_id
= 0xffffffff,
1677 .phy_id_mask
= 0xffffffff,
1678 .name
= "Generic 10G PHY",
1679 .soft_reset
= gen10g_soft_reset
,
1680 .config_init
= gen10g_config_init
,
1682 .config_aneg
= gen10g_config_aneg
,
1683 .read_status
= gen10g_read_status
,
1684 .suspend
= gen10g_suspend
,
1685 .resume
= gen10g_resume
,
1688 static int __init
phy_init(void)
1692 rc
= mdio_bus_init();
1696 rc
= phy_drivers_register(genphy_driver
,
1697 ARRAY_SIZE(genphy_driver
), THIS_MODULE
);
1704 static void __exit
phy_exit(void)
1706 phy_drivers_unregister(genphy_driver
,
1707 ARRAY_SIZE(genphy_driver
));
1711 subsys_initcall(phy_init
);
1712 module_exit(phy_exit
);