Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 1 | /* Framework for configuring and reading PHY devices |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 2 | * Based on code in sungem_phy.c and gianfar_phy.c |
| 3 | * |
| 4 | * Author: Andy Fleming |
| 5 | * |
| 6 | * Copyright (c) 2004 Freescale Semiconductor, Inc. |
Maciej W. Rozycki | 0ac4952 | 2007-09-28 22:42:14 -0700 | [diff] [blame] | 7 | * Copyright (c) 2006, 2007 Maciej W. Rozycki |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | * |
| 14 | */ |
Joe Perches | 8d24248 | 2012-06-09 07:49:07 +0000 | [diff] [blame] | 15 | |
| 16 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 17 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 18 | #include <linux/kernel.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 19 | #include <linux/string.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/unistd.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 23 | #include <linux/delay.h> |
| 24 | #include <linux/netdevice.h> |
| 25 | #include <linux/etherdevice.h> |
| 26 | #include <linux/skbuff.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 27 | #include <linux/mm.h> |
| 28 | #include <linux/module.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 29 | #include <linux/mii.h> |
| 30 | #include <linux/ethtool.h> |
| 31 | #include <linux/phy.h> |
Geert Uytterhoeven | d6f8cfa | 2017-01-25 11:39:49 +0100 | [diff] [blame] | 32 | #include <linux/phy_led_triggers.h> |
Maciej W. Rozycki | 3c3070d | 2006-10-03 16:18:35 +0100 | [diff] [blame] | 33 | #include <linux/timer.h> |
| 34 | #include <linux/workqueue.h> |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 35 | #include <linux/mdio.h> |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 36 | #include <linux/io.h> |
| 37 | #include <linux/uaccess.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 38 | #include <linux/atomic.h> |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 39 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 40 | #include <asm/irq.h> |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 41 | |
Florian Fainelli | 766d1d3 | 2014-02-11 17:27:35 -0800 | [diff] [blame] | 42 | static const char *phy_speed_to_str(int speed) |
| 43 | { |
| 44 | switch (speed) { |
| 45 | case SPEED_10: |
| 46 | return "10Mbps"; |
| 47 | case SPEED_100: |
| 48 | return "100Mbps"; |
| 49 | case SPEED_1000: |
| 50 | return "1Gbps"; |
| 51 | case SPEED_2500: |
| 52 | return "2.5Gbps"; |
Joe Perches | 1f37b17 | 2017-04-02 14:30:06 -0700 | [diff] [blame] | 53 | case SPEED_5000: |
| 54 | return "5Gbps"; |
Florian Fainelli | 766d1d3 | 2014-02-11 17:27:35 -0800 | [diff] [blame] | 55 | case SPEED_10000: |
| 56 | return "10Gbps"; |
Joe Perches | fc5b775d | 2017-06-09 15:45:32 +0200 | [diff] [blame] | 57 | case SPEED_14000: |
| 58 | return "14Gbps"; |
Joe Perches | 1f37b17 | 2017-04-02 14:30:06 -0700 | [diff] [blame] | 59 | case SPEED_20000: |
| 60 | return "20Gbps"; |
| 61 | case SPEED_25000: |
| 62 | return "25Gbps"; |
| 63 | case SPEED_40000: |
| 64 | return "40Gbps"; |
| 65 | case SPEED_50000: |
| 66 | return "50Gbps"; |
| 67 | case SPEED_56000: |
| 68 | return "56Gbps"; |
| 69 | case SPEED_100000: |
| 70 | return "100Gbps"; |
Florian Fainelli | 766d1d3 | 2014-02-11 17:27:35 -0800 | [diff] [blame] | 71 | case SPEED_UNKNOWN: |
| 72 | return "Unknown"; |
| 73 | default: |
| 74 | return "Unsupported (update phy.c)"; |
| 75 | } |
| 76 | } |
| 77 | |
Florian Fainelli | 3e2186e | 2015-05-16 10:17:56 -0700 | [diff] [blame] | 78 | #define PHY_STATE_STR(_state) \ |
| 79 | case PHY_##_state: \ |
| 80 | return __stringify(_state); \ |
| 81 | |
| 82 | static const char *phy_state_to_str(enum phy_state st) |
| 83 | { |
| 84 | switch (st) { |
| 85 | PHY_STATE_STR(DOWN) |
| 86 | PHY_STATE_STR(STARTING) |
| 87 | PHY_STATE_STR(READY) |
| 88 | PHY_STATE_STR(PENDING) |
| 89 | PHY_STATE_STR(UP) |
| 90 | PHY_STATE_STR(AN) |
| 91 | PHY_STATE_STR(RUNNING) |
| 92 | PHY_STATE_STR(NOLINK) |
| 93 | PHY_STATE_STR(FORCING) |
| 94 | PHY_STATE_STR(CHANGELINK) |
| 95 | PHY_STATE_STR(HALTED) |
| 96 | PHY_STATE_STR(RESUMING) |
| 97 | } |
| 98 | |
| 99 | return NULL; |
| 100 | } |
| 101 | |
| 102 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 103 | /** |
| 104 | * phy_print_status - Convenience function to print out the current phy status |
| 105 | * @phydev: the phy_device struct |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 106 | */ |
| 107 | void phy_print_status(struct phy_device *phydev) |
| 108 | { |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 109 | if (phydev->link) { |
Florian Fainelli | df40cc8 | 2014-02-11 17:27:34 -0800 | [diff] [blame] | 110 | netdev_info(phydev->attached_dev, |
Florian Fainelli | 766d1d3 | 2014-02-11 17:27:35 -0800 | [diff] [blame] | 111 | "Link is Up - %s/%s - flow control %s\n", |
| 112 | phy_speed_to_str(phydev->speed), |
Florian Fainelli | df40cc8 | 2014-02-11 17:27:34 -0800 | [diff] [blame] | 113 | DUPLEX_FULL == phydev->duplex ? "Full" : "Half", |
| 114 | phydev->pause ? "rx/tx" : "off"); |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 115 | } else { |
Florian Fainelli | 43b6329 | 2014-02-11 17:27:33 -0800 | [diff] [blame] | 116 | netdev_info(phydev->attached_dev, "Link is Down\n"); |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 117 | } |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 118 | } |
| 119 | EXPORT_SYMBOL(phy_print_status); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 120 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 121 | /** |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 122 | * phy_clear_interrupt - Ack the phy device's interrupt |
| 123 | * @phydev: the phy_device struct |
| 124 | * |
| 125 | * If the @phydev driver has an ack_interrupt function, call it to |
| 126 | * ack and clear the phy device's interrupt. |
| 127 | * |
Florian Fainelli | ad03350 | 2014-02-11 17:27:38 -0800 | [diff] [blame] | 128 | * Returns 0 on success or < 0 on error. |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 129 | */ |
stephen hemminger | 89ff05e | 2010-10-21 08:37:41 +0000 | [diff] [blame] | 130 | static int phy_clear_interrupt(struct phy_device *phydev) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 131 | { |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 132 | if (phydev->drv->ack_interrupt) |
Sergei Shtylyov | e62a768 | 2014-01-05 03:21:52 +0300 | [diff] [blame] | 133 | return phydev->drv->ack_interrupt(phydev); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 134 | |
Sergei Shtylyov | e62a768 | 2014-01-05 03:21:52 +0300 | [diff] [blame] | 135 | return 0; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 138 | /** |
| 139 | * phy_config_interrupt - configure the PHY device for the requested interrupts |
| 140 | * @phydev: the phy_device struct |
| 141 | * @interrupts: interrupt flags to configure for this @phydev |
| 142 | * |
Florian Fainelli | ad03350 | 2014-02-11 17:27:38 -0800 | [diff] [blame] | 143 | * Returns 0 on success or < 0 on error. |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 144 | */ |
stephen hemminger | 89ff05e | 2010-10-21 08:37:41 +0000 | [diff] [blame] | 145 | static int phy_config_interrupt(struct phy_device *phydev, u32 interrupts) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 146 | { |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 147 | phydev->interrupts = interrupts; |
| 148 | if (phydev->drv->config_intr) |
Sergei Shtylyov | e62a768 | 2014-01-05 03:21:52 +0300 | [diff] [blame] | 149 | return phydev->drv->config_intr(phydev); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 150 | |
Sergei Shtylyov | e62a768 | 2014-01-05 03:21:52 +0300 | [diff] [blame] | 151 | return 0; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 155 | /** |
| 156 | * phy_aneg_done - return auto-negotiation status |
| 157 | * @phydev: target phy_device struct |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 158 | * |
Florian Fainelli | 76a423a | 2014-02-11 17:27:37 -0800 | [diff] [blame] | 159 | * Description: Return the auto-negotiation status from this @phydev |
| 160 | * Returns > 0 on success or < 0 on error. 0 means that auto-negotiation |
| 161 | * is still pending. |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 162 | */ |
Lendacky, Thomas | 372788f | 2016-11-10 17:10:46 -0600 | [diff] [blame] | 163 | int phy_aneg_done(struct phy_device *phydev) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 164 | { |
Florian Fainelli | 65f2767 | 2017-02-23 14:22:19 -0800 | [diff] [blame] | 165 | if (phydev->drv && phydev->drv->aneg_done) |
Florian Fainelli | 76a423a | 2014-02-11 17:27:37 -0800 | [diff] [blame] | 166 | return phydev->drv->aneg_done(phydev); |
| 167 | |
Florian Fainelli | a9fa6e6 | 2014-02-11 17:27:36 -0800 | [diff] [blame] | 168 | return genphy_aneg_done(phydev); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 169 | } |
Lendacky, Thomas | 372788f | 2016-11-10 17:10:46 -0600 | [diff] [blame] | 170 | EXPORT_SYMBOL(phy_aneg_done); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 171 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 172 | /* A structure for mapping a particular speed and duplex |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 173 | * combination to a particular SUPPORTED and ADVERTISED value |
| 174 | */ |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 175 | struct phy_setting { |
| 176 | int speed; |
| 177 | int duplex; |
| 178 | u32 setting; |
| 179 | }; |
| 180 | |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 181 | /* A mapping of all SUPPORTED settings to speed/duplex. This table |
| 182 | * must be grouped by speed and sorted in descending match priority |
| 183 | * - iow, descending speed. */ |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 184 | static const struct phy_setting settings[] = { |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 185 | { |
Lendacky, Thomas | 3e70770 | 2014-07-14 14:05:46 -0500 | [diff] [blame] | 186 | .speed = SPEED_10000, |
| 187 | .duplex = DUPLEX_FULL, |
| 188 | .setting = SUPPORTED_10000baseKR_Full, |
| 189 | }, |
| 190 | { |
| 191 | .speed = SPEED_10000, |
| 192 | .duplex = DUPLEX_FULL, |
| 193 | .setting = SUPPORTED_10000baseKX4_Full, |
| 194 | }, |
| 195 | { |
| 196 | .speed = SPEED_10000, |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 197 | .duplex = DUPLEX_FULL, |
| 198 | .setting = SUPPORTED_10000baseT_Full, |
| 199 | }, |
| 200 | { |
Lendacky, Thomas | 3e70770 | 2014-07-14 14:05:46 -0500 | [diff] [blame] | 201 | .speed = SPEED_2500, |
| 202 | .duplex = DUPLEX_FULL, |
| 203 | .setting = SUPPORTED_2500baseX_Full, |
| 204 | }, |
| 205 | { |
| 206 | .speed = SPEED_1000, |
| 207 | .duplex = DUPLEX_FULL, |
| 208 | .setting = SUPPORTED_1000baseKX_Full, |
| 209 | }, |
| 210 | { |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 211 | .speed = SPEED_1000, |
| 212 | .duplex = DUPLEX_FULL, |
| 213 | .setting = SUPPORTED_1000baseT_Full, |
| 214 | }, |
| 215 | { |
| 216 | .speed = SPEED_1000, |
| 217 | .duplex = DUPLEX_HALF, |
| 218 | .setting = SUPPORTED_1000baseT_Half, |
| 219 | }, |
| 220 | { |
| 221 | .speed = SPEED_100, |
| 222 | .duplex = DUPLEX_FULL, |
| 223 | .setting = SUPPORTED_100baseT_Full, |
| 224 | }, |
| 225 | { |
| 226 | .speed = SPEED_100, |
| 227 | .duplex = DUPLEX_HALF, |
| 228 | .setting = SUPPORTED_100baseT_Half, |
| 229 | }, |
| 230 | { |
| 231 | .speed = SPEED_10, |
| 232 | .duplex = DUPLEX_FULL, |
| 233 | .setting = SUPPORTED_10baseT_Full, |
| 234 | }, |
| 235 | { |
| 236 | .speed = SPEED_10, |
| 237 | .duplex = DUPLEX_HALF, |
| 238 | .setting = SUPPORTED_10baseT_Half, |
| 239 | }, |
| 240 | }; |
| 241 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 242 | /** |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 243 | * phy_lookup_setting - lookup a PHY setting |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 244 | * @speed: speed to match |
| 245 | * @duplex: duplex to match |
Randy Dunlap | 6c6ab3e | 2017-06-04 19:46:53 -0700 | [diff] [blame] | 246 | * @features: allowed link modes |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 247 | * @exact: an exact match is required |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 248 | * |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 249 | * Search the settings array for a setting that matches the speed and |
| 250 | * duplex, and which is supported. |
| 251 | * |
| 252 | * If @exact is unset, either an exact match or %NULL for no match will |
| 253 | * be returned. |
| 254 | * |
| 255 | * If @exact is set, an exact match, the fastest supported setting at |
| 256 | * or below the specified speed, the slowest supported setting, or if |
| 257 | * they all fail, %NULL will be returned. |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 258 | */ |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 259 | static const struct phy_setting * |
| 260 | phy_lookup_setting(int speed, int duplex, u32 features, bool exact) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 261 | { |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 262 | const struct phy_setting *p, *match = NULL, *last = NULL; |
| 263 | int i; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 264 | |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 265 | for (i = 0, p = settings; i < ARRAY_SIZE(settings); i++, p++) { |
| 266 | if (p->setting & features) { |
| 267 | last = p; |
| 268 | if (p->speed == speed && p->duplex == duplex) { |
| 269 | /* Exact match for speed and duplex */ |
| 270 | match = p; |
| 271 | break; |
| 272 | } else if (!exact) { |
| 273 | if (!match && p->speed <= speed) |
| 274 | /* Candidate */ |
| 275 | match = p; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 276 | |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 277 | if (p->speed < speed) |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | if (!match && !exact) |
| 284 | match = last; |
| 285 | |
| 286 | return match; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 287 | } |
| 288 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 289 | /** |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 290 | * phy_find_valid - find a PHY setting that matches the requested parameters |
| 291 | * @speed: desired speed |
| 292 | * @duplex: desired duplex |
| 293 | * @supported: mask of supported link modes |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 294 | * |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 295 | * Locate a supported phy setting that is, in priority order: |
| 296 | * - an exact match for the specified speed and duplex mode |
| 297 | * - a match for the specified speed, or slower speed |
| 298 | * - the slowest supported speed |
| 299 | * Returns the matched phy_setting entry, or %NULL if no supported phy |
| 300 | * settings were found. |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 301 | */ |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 302 | static const struct phy_setting * |
| 303 | phy_find_valid(int speed, int duplex, u32 supported) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 304 | { |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 305 | return phy_lookup_setting(speed, duplex, supported, false); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 308 | /** |
Zach Brown | 1f9127c | 2016-10-17 10:49:54 -0500 | [diff] [blame] | 309 | * phy_supported_speeds - return all speeds currently supported by a phy device |
| 310 | * @phy: The phy device to return supported speeds of. |
| 311 | * @speeds: buffer to store supported speeds in. |
| 312 | * @size: size of speeds buffer. |
| 313 | * |
| 314 | * Description: Returns the number of supported speeds, and fills the speeds |
| 315 | * buffer with the supported speeds. If speeds buffer is too small to contain |
| 316 | * all currently supported speeds, will return as many speeds as can fit. |
| 317 | */ |
| 318 | unsigned int phy_supported_speeds(struct phy_device *phy, |
| 319 | unsigned int *speeds, |
| 320 | unsigned int size) |
| 321 | { |
| 322 | unsigned int count = 0; |
| 323 | unsigned int idx = 0; |
| 324 | |
Russell King | 786df9c | 2017-04-13 16:49:20 +0100 | [diff] [blame] | 325 | for (idx = 0; idx < ARRAY_SIZE(settings) && count < size; idx++) |
Zach Brown | 1f9127c | 2016-10-17 10:49:54 -0500 | [diff] [blame] | 326 | /* Assumes settings are grouped by speed */ |
Russell King | 786df9c | 2017-04-13 16:49:20 +0100 | [diff] [blame] | 327 | if ((settings[idx].setting & phy->supported) && |
| 328 | (count == 0 || speeds[count - 1] != settings[idx].speed)) |
| 329 | speeds[count++] = settings[idx].speed; |
Zach Brown | 1f9127c | 2016-10-17 10:49:54 -0500 | [diff] [blame] | 330 | |
| 331 | return count; |
| 332 | } |
| 333 | |
| 334 | /** |
Guenter Roeck | 54da5a8 | 2015-02-17 09:36:22 -0800 | [diff] [blame] | 335 | * phy_check_valid - check if there is a valid PHY setting which matches |
| 336 | * speed, duplex, and feature mask |
| 337 | * @speed: speed to match |
| 338 | * @duplex: duplex to match |
| 339 | * @features: A mask of the valid settings |
| 340 | * |
| 341 | * Description: Returns true if there is a valid setting, false otherwise. |
| 342 | */ |
| 343 | static inline bool phy_check_valid(int speed, int duplex, u32 features) |
| 344 | { |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 345 | return !!phy_lookup_setting(speed, duplex, features, true); |
Guenter Roeck | 54da5a8 | 2015-02-17 09:36:22 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | /** |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 349 | * phy_sanitize_settings - make sure the PHY is set to supported speed and duplex |
| 350 | * @phydev: the target phy_device struct |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 351 | * |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 352 | * Description: Make sure the PHY is set to supported speeds and |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 353 | * duplexes. Drop down by one in this order: 1000/FULL, |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 354 | * 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF. |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 355 | */ |
stephen hemminger | 89ff05e | 2010-10-21 08:37:41 +0000 | [diff] [blame] | 356 | static void phy_sanitize_settings(struct phy_device *phydev) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 357 | { |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 358 | const struct phy_setting *setting; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 359 | u32 features = phydev->supported; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 360 | |
| 361 | /* Sanitize settings based on PHY capabilities */ |
| 362 | if ((features & SUPPORTED_Autoneg) == 0) |
Domen Puncer | 163642a | 2007-08-07 12:12:41 +0200 | [diff] [blame] | 363 | phydev->autoneg = AUTONEG_DISABLE; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 364 | |
Russell King | d061303 | 2017-04-13 16:49:15 +0100 | [diff] [blame] | 365 | setting = phy_find_valid(phydev->speed, phydev->duplex, features); |
| 366 | if (setting) { |
| 367 | phydev->speed = setting->speed; |
| 368 | phydev->duplex = setting->duplex; |
| 369 | } else { |
| 370 | /* We failed to find anything (no supported speeds?) */ |
| 371 | phydev->speed = SPEED_UNKNOWN; |
| 372 | phydev->duplex = DUPLEX_UNKNOWN; |
| 373 | } |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 374 | } |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 375 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 376 | /** |
| 377 | * phy_ethtool_sset - generic ethtool sset function, handles all the details |
| 378 | * @phydev: target phy_device struct |
| 379 | * @cmd: ethtool_cmd |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 380 | * |
| 381 | * A few notes about parameter checking: |
| 382 | * - We don't set port or transceiver, so we don't care what they |
| 383 | * were set to. |
| 384 | * - phy_start_aneg() will make sure forced settings are sane, and |
| 385 | * choose the next best ones from the ones selected, so we don't |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 386 | * care if ethtool tries to give us bad values. |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 387 | */ |
| 388 | int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd) |
| 389 | { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 390 | u32 speed = ethtool_cmd_speed(cmd); |
| 391 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 392 | if (cmd->phy_address != phydev->mdio.addr) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 393 | return -EINVAL; |
| 394 | |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 395 | /* We make sure that we don't pass unsupported values in to the PHY */ |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 396 | cmd->advertising &= phydev->supported; |
| 397 | |
| 398 | /* Verify the settings we care about. */ |
| 399 | if (cmd->autoneg != AUTONEG_ENABLE && cmd->autoneg != AUTONEG_DISABLE) |
| 400 | return -EINVAL; |
| 401 | |
| 402 | if (cmd->autoneg == AUTONEG_ENABLE && cmd->advertising == 0) |
| 403 | return -EINVAL; |
| 404 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 405 | if (cmd->autoneg == AUTONEG_DISABLE && |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 406 | ((speed != SPEED_1000 && |
| 407 | speed != SPEED_100 && |
| 408 | speed != SPEED_10) || |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 409 | (cmd->duplex != DUPLEX_HALF && |
| 410 | cmd->duplex != DUPLEX_FULL))) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 411 | return -EINVAL; |
| 412 | |
| 413 | phydev->autoneg = cmd->autoneg; |
| 414 | |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 415 | phydev->speed = speed; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 416 | |
| 417 | phydev->advertising = cmd->advertising; |
| 418 | |
| 419 | if (AUTONEG_ENABLE == cmd->autoneg) |
| 420 | phydev->advertising |= ADVERTISED_Autoneg; |
| 421 | else |
| 422 | phydev->advertising &= ~ADVERTISED_Autoneg; |
| 423 | |
| 424 | phydev->duplex = cmd->duplex; |
| 425 | |
Raju Lakkaraju | 1004ee6 | 2016-11-29 15:16:47 +0530 | [diff] [blame] | 426 | phydev->mdix_ctrl = cmd->eth_tp_mdix_ctrl; |
David Thomson | 634ec36 | 2015-07-10 13:56:54 +1200 | [diff] [blame] | 427 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 428 | /* Restart the PHY */ |
| 429 | phy_start_aneg(phydev); |
| 430 | |
| 431 | return 0; |
| 432 | } |
Kumar Gala | 9f6d55d | 2007-01-20 16:38:26 -0600 | [diff] [blame] | 433 | EXPORT_SYMBOL(phy_ethtool_sset); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 434 | |
Philippe Reynes | 2d55173 | 2016-04-15 00:35:00 +0200 | [diff] [blame] | 435 | int phy_ethtool_ksettings_set(struct phy_device *phydev, |
| 436 | const struct ethtool_link_ksettings *cmd) |
| 437 | { |
| 438 | u8 autoneg = cmd->base.autoneg; |
| 439 | u8 duplex = cmd->base.duplex; |
| 440 | u32 speed = cmd->base.speed; |
| 441 | u32 advertising; |
| 442 | |
| 443 | if (cmd->base.phy_address != phydev->mdio.addr) |
| 444 | return -EINVAL; |
| 445 | |
| 446 | ethtool_convert_link_mode_to_legacy_u32(&advertising, |
| 447 | cmd->link_modes.advertising); |
| 448 | |
| 449 | /* We make sure that we don't pass unsupported values in to the PHY */ |
| 450 | advertising &= phydev->supported; |
| 451 | |
| 452 | /* Verify the settings we care about. */ |
| 453 | if (autoneg != AUTONEG_ENABLE && autoneg != AUTONEG_DISABLE) |
| 454 | return -EINVAL; |
| 455 | |
| 456 | if (autoneg == AUTONEG_ENABLE && advertising == 0) |
| 457 | return -EINVAL; |
| 458 | |
| 459 | if (autoneg == AUTONEG_DISABLE && |
| 460 | ((speed != SPEED_1000 && |
| 461 | speed != SPEED_100 && |
| 462 | speed != SPEED_10) || |
| 463 | (duplex != DUPLEX_HALF && |
| 464 | duplex != DUPLEX_FULL))) |
| 465 | return -EINVAL; |
| 466 | |
| 467 | phydev->autoneg = autoneg; |
| 468 | |
| 469 | phydev->speed = speed; |
| 470 | |
| 471 | phydev->advertising = advertising; |
| 472 | |
| 473 | if (autoneg == AUTONEG_ENABLE) |
| 474 | phydev->advertising |= ADVERTISED_Autoneg; |
| 475 | else |
| 476 | phydev->advertising &= ~ADVERTISED_Autoneg; |
| 477 | |
| 478 | phydev->duplex = duplex; |
| 479 | |
Raju Lakkaraju | 1004ee6 | 2016-11-29 15:16:47 +0530 | [diff] [blame] | 480 | phydev->mdix_ctrl = cmd->base.eth_tp_mdix_ctrl; |
Philippe Reynes | 2d55173 | 2016-04-15 00:35:00 +0200 | [diff] [blame] | 481 | |
| 482 | /* Restart the PHY */ |
| 483 | phy_start_aneg(phydev); |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | EXPORT_SYMBOL(phy_ethtool_ksettings_set); |
| 488 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 489 | int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd) |
| 490 | { |
| 491 | cmd->supported = phydev->supported; |
| 492 | |
| 493 | cmd->advertising = phydev->advertising; |
Florian Fainelli | 114002b | 2013-12-06 13:01:30 -0800 | [diff] [blame] | 494 | cmd->lp_advertising = phydev->lp_advertising; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 495 | |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 496 | ethtool_cmd_speed_set(cmd, phydev->speed); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 497 | cmd->duplex = phydev->duplex; |
Florian Fainelli | c88838c | 2014-02-13 16:08:43 -0800 | [diff] [blame] | 498 | if (phydev->interface == PHY_INTERFACE_MODE_MOCA) |
| 499 | cmd->port = PORT_BNC; |
| 500 | else |
| 501 | cmd->port = PORT_MII; |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 502 | cmd->phy_address = phydev->mdio.addr; |
Florian Fainelli | 4284b6a | 2013-05-23 01:11:12 +0000 | [diff] [blame] | 503 | cmd->transceiver = phy_is_internal(phydev) ? |
| 504 | XCVR_INTERNAL : XCVR_EXTERNAL; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 505 | cmd->autoneg = phydev->autoneg; |
Raju Lakkaraju | 1004ee6 | 2016-11-29 15:16:47 +0530 | [diff] [blame] | 506 | cmd->eth_tp_mdix_ctrl = phydev->mdix_ctrl; |
| 507 | cmd->eth_tp_mdix = phydev->mdix; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 508 | |
| 509 | return 0; |
| 510 | } |
Kumar Gala | 9f6d55d | 2007-01-20 16:38:26 -0600 | [diff] [blame] | 511 | EXPORT_SYMBOL(phy_ethtool_gset); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 512 | |
Philippe Reynes | 2d55173 | 2016-04-15 00:35:00 +0200 | [diff] [blame] | 513 | int phy_ethtool_ksettings_get(struct phy_device *phydev, |
| 514 | struct ethtool_link_ksettings *cmd) |
| 515 | { |
| 516 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 517 | phydev->supported); |
| 518 | |
| 519 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 520 | phydev->advertising); |
| 521 | |
| 522 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.lp_advertising, |
| 523 | phydev->lp_advertising); |
| 524 | |
| 525 | cmd->base.speed = phydev->speed; |
| 526 | cmd->base.duplex = phydev->duplex; |
| 527 | if (phydev->interface == PHY_INTERFACE_MODE_MOCA) |
| 528 | cmd->base.port = PORT_BNC; |
| 529 | else |
| 530 | cmd->base.port = PORT_MII; |
| 531 | |
| 532 | cmd->base.phy_address = phydev->mdio.addr; |
| 533 | cmd->base.autoneg = phydev->autoneg; |
Raju Lakkaraju | 1004ee6 | 2016-11-29 15:16:47 +0530 | [diff] [blame] | 534 | cmd->base.eth_tp_mdix_ctrl = phydev->mdix_ctrl; |
| 535 | cmd->base.eth_tp_mdix = phydev->mdix; |
Philippe Reynes | 2d55173 | 2016-04-15 00:35:00 +0200 | [diff] [blame] | 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | EXPORT_SYMBOL(phy_ethtool_ksettings_get); |
| 540 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 541 | /** |
| 542 | * phy_mii_ioctl - generic PHY MII ioctl interface |
| 543 | * @phydev: the phy_device struct |
Randy Dunlap | 00c7d92 | 2010-08-09 13:41:59 +0000 | [diff] [blame] | 544 | * @ifr: &struct ifreq for socket ioctl's |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 545 | * @cmd: ioctl cmd to execute |
| 546 | * |
| 547 | * Note that this function is currently incompatible with the |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 548 | * PHYCONTROL layer. It changes registers without regard to |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 549 | * current state. Use at own risk. |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 550 | */ |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 551 | int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 552 | { |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 553 | struct mii_ioctl_data *mii_data = if_mii(ifr); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 554 | u16 val = mii_data->val_in; |
Brian Hill | 79ce047 | 2014-11-11 13:39:39 -0700 | [diff] [blame] | 555 | bool change_autoneg = false; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 556 | |
| 557 | switch (cmd) { |
| 558 | case SIOCGMIIPHY: |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 559 | mii_data->phy_id = phydev->mdio.addr; |
Lennert Buytenhek | c6d6a51 | 2008-09-18 03:06:52 +0000 | [diff] [blame] | 560 | /* fall through */ |
| 561 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 562 | case SIOCGMIIREG: |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 563 | mii_data->val_out = mdiobus_read(phydev->mdio.bus, |
| 564 | mii_data->phy_id, |
Peter Korsgaard | af1dc13 | 2011-03-10 06:52:13 +0000 | [diff] [blame] | 565 | mii_data->reg_num); |
Sergei Shtylyov | e62a768 | 2014-01-05 03:21:52 +0300 | [diff] [blame] | 566 | return 0; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 567 | |
| 568 | case SIOCSMIIREG: |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 569 | if (mii_data->phy_id == phydev->mdio.addr) { |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 570 | switch (mii_data->reg_num) { |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 571 | case MII_BMCR: |
Brian Hill | 79ce047 | 2014-11-11 13:39:39 -0700 | [diff] [blame] | 572 | if ((val & (BMCR_RESET | BMCR_ANENABLE)) == 0) { |
| 573 | if (phydev->autoneg == AUTONEG_ENABLE) |
| 574 | change_autoneg = true; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 575 | phydev->autoneg = AUTONEG_DISABLE; |
Brian Hill | 79ce047 | 2014-11-11 13:39:39 -0700 | [diff] [blame] | 576 | if (val & BMCR_FULLDPLX) |
| 577 | phydev->duplex = DUPLEX_FULL; |
| 578 | else |
| 579 | phydev->duplex = DUPLEX_HALF; |
| 580 | if (val & BMCR_SPEED1000) |
| 581 | phydev->speed = SPEED_1000; |
| 582 | else if (val & BMCR_SPEED100) |
| 583 | phydev->speed = SPEED_100; |
| 584 | else phydev->speed = SPEED_10; |
| 585 | } |
| 586 | else { |
| 587 | if (phydev->autoneg == AUTONEG_DISABLE) |
| 588 | change_autoneg = true; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 589 | phydev->autoneg = AUTONEG_ENABLE; |
Brian Hill | 79ce047 | 2014-11-11 13:39:39 -0700 | [diff] [blame] | 590 | } |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 591 | break; |
| 592 | case MII_ADVERTISE: |
Brian Hill | 79ce047 | 2014-11-11 13:39:39 -0700 | [diff] [blame] | 593 | phydev->advertising = mii_adv_to_ethtool_adv_t(val); |
| 594 | change_autoneg = true; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 595 | break; |
| 596 | default: |
| 597 | /* do nothing */ |
| 598 | break; |
| 599 | } |
| 600 | } |
| 601 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 602 | mdiobus_write(phydev->mdio.bus, mii_data->phy_id, |
Peter Korsgaard | af1dc13 | 2011-03-10 06:52:13 +0000 | [diff] [blame] | 603 | mii_data->reg_num, val); |
| 604 | |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 605 | if (mii_data->phy_id == phydev->mdio.addr && |
Jérôme Pouiller | cf18b77 | 2015-12-03 10:02:35 +0100 | [diff] [blame] | 606 | mii_data->reg_num == MII_BMCR && |
Florian Fainelli | 2613f95 | 2013-12-06 13:01:31 -0800 | [diff] [blame] | 607 | val & BMCR_RESET) |
Sergei Shtylyov | e62a768 | 2014-01-05 03:21:52 +0300 | [diff] [blame] | 608 | return phy_init_hw(phydev); |
Brian Hill | 79ce047 | 2014-11-11 13:39:39 -0700 | [diff] [blame] | 609 | |
| 610 | if (change_autoneg) |
| 611 | return phy_start_aneg(phydev); |
| 612 | |
Sergei Shtylyov | e62a768 | 2014-01-05 03:21:52 +0300 | [diff] [blame] | 613 | return 0; |
David Woodhouse | dda93b4 | 2007-11-28 19:56:34 +0000 | [diff] [blame] | 614 | |
Richard Cochran | c1f19b5 | 2010-07-17 08:49:36 +0000 | [diff] [blame] | 615 | case SIOCSHWTSTAMP: |
Florian Fainelli | 25149ef | 2017-02-17 16:07:34 -0800 | [diff] [blame] | 616 | if (phydev->drv && phydev->drv->hwtstamp) |
Richard Cochran | c1f19b5 | 2010-07-17 08:49:36 +0000 | [diff] [blame] | 617 | return phydev->drv->hwtstamp(phydev, ifr); |
| 618 | /* fall through */ |
| 619 | |
David Woodhouse | dda93b4 | 2007-11-28 19:56:34 +0000 | [diff] [blame] | 620 | default: |
Lennert Buytenhek | c6d6a51 | 2008-09-18 03:06:52 +0000 | [diff] [blame] | 621 | return -EOPNOTSUPP; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 622 | } |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 623 | } |
Domen Puncer | 680e9fe | 2007-09-17 22:21:40 +0200 | [diff] [blame] | 624 | EXPORT_SYMBOL(phy_mii_ioctl); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 625 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 626 | /** |
Alexander Kochetkov | f555f34 | 2017-04-20 14:00:04 +0300 | [diff] [blame] | 627 | * phy_start_aneg_priv - start auto-negotiation for this PHY device |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 628 | * @phydev: the phy_device struct |
Alexander Kochetkov | f555f34 | 2017-04-20 14:00:04 +0300 | [diff] [blame] | 629 | * @sync: indicate whether we should wait for the workqueue cancelation |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 630 | * |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 631 | * Description: Sanitizes the settings (if we're not autonegotiating |
| 632 | * them), and then calls the driver's config_aneg function. |
| 633 | * If the PHYCONTROL Layer is operating, we change the state to |
| 634 | * reflect the beginning of Auto-negotiation or forcing. |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 635 | */ |
Alexander Kochetkov | f555f34 | 2017-04-20 14:00:04 +0300 | [diff] [blame] | 636 | static int phy_start_aneg_priv(struct phy_device *phydev, bool sync) |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 637 | { |
Alexander Kochetkov | f555f34 | 2017-04-20 14:00:04 +0300 | [diff] [blame] | 638 | bool trigger = 0; |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 639 | int err; |
| 640 | |
Florian Fainelli | 25149ef | 2017-02-17 16:07:34 -0800 | [diff] [blame] | 641 | if (!phydev->drv) |
| 642 | return -EIO; |
| 643 | |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 644 | mutex_lock(&phydev->lock); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 645 | |
| 646 | if (AUTONEG_DISABLE == phydev->autoneg) |
| 647 | phy_sanitize_settings(phydev); |
| 648 | |
Ben Hutchings | 9b3320e | 2015-01-27 00:58:15 +0000 | [diff] [blame] | 649 | /* Invalidate LP advertising flags */ |
| 650 | phydev->lp_advertising = 0; |
| 651 | |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 652 | err = phydev->drv->config_aneg(phydev); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 653 | if (err < 0) |
| 654 | goto out_unlock; |
| 655 | |
| 656 | if (phydev->state != PHY_HALTED) { |
| 657 | if (AUTONEG_ENABLE == phydev->autoneg) { |
| 658 | phydev->state = PHY_AN; |
| 659 | phydev->link_timeout = PHY_AN_TIMEOUT; |
| 660 | } else { |
| 661 | phydev->state = PHY_FORCING; |
| 662 | phydev->link_timeout = PHY_FORCE_TIMEOUT; |
| 663 | } |
| 664 | } |
| 665 | |
Alexander Kochetkov | f555f34 | 2017-04-20 14:00:04 +0300 | [diff] [blame] | 666 | /* Re-schedule a PHY state machine to check PHY status because |
| 667 | * negotiation may already be done and aneg interrupt may not be |
| 668 | * generated. |
| 669 | */ |
| 670 | if (phy_interrupt_is_valid(phydev) && (phydev->state == PHY_AN)) { |
| 671 | err = phy_aneg_done(phydev); |
| 672 | if (err > 0) { |
| 673 | trigger = true; |
| 674 | err = 0; |
| 675 | } |
| 676 | } |
| 677 | |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 678 | out_unlock: |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 679 | mutex_unlock(&phydev->lock); |
Alexander Kochetkov | f555f34 | 2017-04-20 14:00:04 +0300 | [diff] [blame] | 680 | |
| 681 | if (trigger) |
| 682 | phy_trigger_machine(phydev, sync); |
| 683 | |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 684 | return err; |
| 685 | } |
Alexander Kochetkov | f555f34 | 2017-04-20 14:00:04 +0300 | [diff] [blame] | 686 | |
| 687 | /** |
| 688 | * phy_start_aneg - start auto-negotiation for this PHY device |
| 689 | * @phydev: the phy_device struct |
| 690 | * |
| 691 | * Description: Sanitizes the settings (if we're not autonegotiating |
| 692 | * them), and then calls the driver's config_aneg function. |
| 693 | * If the PHYCONTROL Layer is operating, we change the state to |
| 694 | * reflect the beginning of Auto-negotiation or forcing. |
| 695 | */ |
| 696 | int phy_start_aneg(struct phy_device *phydev) |
| 697 | { |
| 698 | return phy_start_aneg_priv(phydev, true); |
| 699 | } |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 700 | EXPORT_SYMBOL(phy_start_aneg); |
| 701 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 702 | /** |
| 703 | * phy_start_machine - start PHY state machine tracking |
| 704 | * @phydev: the phy_device struct |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 705 | * |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 706 | * Description: The PHY infrastructure can run a state machine |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 707 | * which tracks whether the PHY is starting up, negotiating, |
| 708 | * etc. This function starts the timer which tracks the state |
Sergei Shtylyov | 29935ae | 2014-01-05 03:27:17 +0300 | [diff] [blame] | 709 | * of the PHY. If you want to maintain your own state machine, |
| 710 | * do not call this function. |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 711 | */ |
Sergei Shtylyov | 29935ae | 2014-01-05 03:27:17 +0300 | [diff] [blame] | 712 | void phy_start_machine(struct phy_device *phydev) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 713 | { |
Viresh Kumar | bbb47bd | 2013-04-24 17:12:55 +0530 | [diff] [blame] | 714 | queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, HZ); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 715 | } |
| 716 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 717 | /** |
Andrew Lunn | 3c293f4 | 2016-10-12 22:14:53 +0200 | [diff] [blame] | 718 | * phy_trigger_machine - trigger the state machine to run |
| 719 | * |
| 720 | * @phydev: the phy_device struct |
Florian Fainelli | eab1277 | 2017-01-20 15:31:52 -0800 | [diff] [blame] | 721 | * @sync: indicate whether we should wait for the workqueue cancelation |
Andrew Lunn | 3c293f4 | 2016-10-12 22:14:53 +0200 | [diff] [blame] | 722 | * |
| 723 | * Description: There has been a change in state which requires that the |
| 724 | * state machine runs. |
| 725 | */ |
| 726 | |
Alexander Kochetkov | f555f34 | 2017-04-20 14:00:04 +0300 | [diff] [blame] | 727 | void phy_trigger_machine(struct phy_device *phydev, bool sync) |
Andrew Lunn | 3c293f4 | 2016-10-12 22:14:53 +0200 | [diff] [blame] | 728 | { |
Florian Fainelli | eab1277 | 2017-01-20 15:31:52 -0800 | [diff] [blame] | 729 | if (sync) |
| 730 | cancel_delayed_work_sync(&phydev->state_queue); |
| 731 | else |
| 732 | cancel_delayed_work(&phydev->state_queue); |
Andrew Lunn | 3c293f4 | 2016-10-12 22:14:53 +0200 | [diff] [blame] | 733 | queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, 0); |
| 734 | } |
| 735 | |
| 736 | /** |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 737 | * phy_stop_machine - stop the PHY state machine tracking |
| 738 | * @phydev: target phy_device struct |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 739 | * |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 740 | * Description: Stops the state machine timer, sets the state to UP |
Sergei Shtylylov | 817acf5 | 2006-07-26 00:53:53 +0400 | [diff] [blame] | 741 | * (unless it wasn't up yet). This function must be called BEFORE |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 742 | * phy_detach. |
| 743 | */ |
| 744 | void phy_stop_machine(struct phy_device *phydev) |
| 745 | { |
Marcin Slusarz | a390d1f | 2009-03-13 15:41:19 -0700 | [diff] [blame] | 746 | cancel_delayed_work_sync(&phydev->state_queue); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 747 | |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 748 | mutex_lock(&phydev->lock); |
Nathan Sullivan | 49d52e8 | 2017-03-22 15:27:01 -0500 | [diff] [blame] | 749 | if (phydev->state > PHY_UP && phydev->state != PHY_HALTED) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 750 | phydev->state = PHY_UP; |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 751 | mutex_unlock(&phydev->lock); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 752 | } |
| 753 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 754 | /** |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 755 | * phy_error - enter HALTED state for this PHY device |
| 756 | * @phydev: target phy_device struct |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 757 | * |
| 758 | * Moves the PHY to the HALTED state in response to a read |
| 759 | * or write error, and tells the controller the link is down. |
| 760 | * Must not be called from interrupt context, or while the |
| 761 | * phydev->lock is held. |
| 762 | */ |
Andy Fleming | 9b9a8bf | 2008-05-02 13:00:51 -0500 | [diff] [blame] | 763 | static void phy_error(struct phy_device *phydev) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 764 | { |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 765 | mutex_lock(&phydev->lock); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 766 | phydev->state = PHY_HALTED; |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 767 | mutex_unlock(&phydev->lock); |
Andrew Lunn | 3c293f4 | 2016-10-12 22:14:53 +0200 | [diff] [blame] | 768 | |
Florian Fainelli | eab1277 | 2017-01-20 15:31:52 -0800 | [diff] [blame] | 769 | phy_trigger_machine(phydev, false); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 770 | } |
| 771 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 772 | /** |
| 773 | * phy_interrupt - PHY interrupt handler |
| 774 | * @irq: interrupt line |
| 775 | * @phy_dat: phy_device pointer |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 776 | * |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 777 | * Description: When a PHY interrupt occurs, the handler disables |
Andrew Lunn | 664fcf1 | 2016-10-16 19:56:51 +0200 | [diff] [blame] | 778 | * interrupts, and uses phy_change to handle the interrupt. |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 779 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 780 | static irqreturn_t phy_interrupt(int irq, void *phy_dat) |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 781 | { |
| 782 | struct phy_device *phydev = phy_dat; |
| 783 | |
Maciej W. Rozycki | 3c3070d | 2006-10-03 16:18:35 +0100 | [diff] [blame] | 784 | if (PHY_HALTED == phydev->state) |
| 785 | return IRQ_NONE; /* It can't be ours. */ |
| 786 | |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 787 | disable_irq_nosync(irq); |
Maciej W. Rozycki | 0ac4952 | 2007-09-28 22:42:14 -0700 | [diff] [blame] | 788 | atomic_inc(&phydev->irq_disable); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 789 | |
Andrew Lunn | 664fcf1 | 2016-10-16 19:56:51 +0200 | [diff] [blame] | 790 | phy_change(phydev); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 791 | |
| 792 | return IRQ_HANDLED; |
| 793 | } |
| 794 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 795 | /** |
| 796 | * phy_enable_interrupts - Enable the interrupts from the PHY side |
| 797 | * @phydev: target phy_device struct |
| 798 | */ |
stephen hemminger | 89ff05e | 2010-10-21 08:37:41 +0000 | [diff] [blame] | 799 | static int phy_enable_interrupts(struct phy_device *phydev) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 800 | { |
Sergei Shtylyov | 553fe92 | 2014-01-05 03:23:19 +0300 | [diff] [blame] | 801 | int err = phy_clear_interrupt(phydev); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 802 | |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 803 | if (err < 0) |
| 804 | return err; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 805 | |
Sergei Shtylyov | 553fe92 | 2014-01-05 03:23:19 +0300 | [diff] [blame] | 806 | return phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 807 | } |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 808 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 809 | /** |
| 810 | * phy_disable_interrupts - Disable the PHY interrupts from the PHY side |
| 811 | * @phydev: target phy_device struct |
| 812 | */ |
stephen hemminger | 89ff05e | 2010-10-21 08:37:41 +0000 | [diff] [blame] | 813 | static int phy_disable_interrupts(struct phy_device *phydev) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 814 | { |
| 815 | int err; |
| 816 | |
| 817 | /* Disable PHY interrupts */ |
| 818 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 819 | if (err) |
| 820 | goto phy_err; |
| 821 | |
| 822 | /* Clear the interrupt */ |
| 823 | err = phy_clear_interrupt(phydev); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 824 | if (err) |
| 825 | goto phy_err; |
| 826 | |
| 827 | return 0; |
| 828 | |
| 829 | phy_err: |
| 830 | phy_error(phydev); |
| 831 | |
| 832 | return err; |
| 833 | } |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 834 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 835 | /** |
| 836 | * phy_start_interrupts - request and enable interrupts for a PHY device |
| 837 | * @phydev: target phy_device struct |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 838 | * |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 839 | * Description: Request the interrupt for the given PHY. |
| 840 | * If this fails, then we set irq to PHY_POLL. |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 841 | * Otherwise, we enable the interrupts in the PHY. |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 842 | * This should only be called with a valid IRQ number. |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 843 | * Returns 0 on success or < 0 on error. |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 844 | */ |
| 845 | int phy_start_interrupts(struct phy_device *phydev) |
| 846 | { |
Maciej W. Rozycki | 0ac4952 | 2007-09-28 22:42:14 -0700 | [diff] [blame] | 847 | atomic_set(&phydev->irq_disable, 0); |
Andrew Lunn | c974bdb | 2016-10-16 19:56:50 +0200 | [diff] [blame] | 848 | if (request_threaded_irq(phydev->irq, NULL, phy_interrupt, |
| 849 | IRQF_ONESHOT | IRQF_SHARED, |
Andrew Lunn | ae0219c | 2016-10-16 19:56:52 +0200 | [diff] [blame] | 850 | phydev_name(phydev), phydev) < 0) { |
Joe Perches | 8d24248 | 2012-06-09 07:49:07 +0000 | [diff] [blame] | 851 | pr_warn("%s: Can't get IRQ %d (PHY)\n", |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 852 | phydev->mdio.bus->name, phydev->irq); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 853 | phydev->irq = PHY_POLL; |
| 854 | return 0; |
| 855 | } |
| 856 | |
Sergei Shtylyov | e62a768 | 2014-01-05 03:21:52 +0300 | [diff] [blame] | 857 | return phy_enable_interrupts(phydev); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 858 | } |
| 859 | EXPORT_SYMBOL(phy_start_interrupts); |
| 860 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 861 | /** |
| 862 | * phy_stop_interrupts - disable interrupts from a PHY device |
| 863 | * @phydev: target phy_device struct |
| 864 | */ |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 865 | int phy_stop_interrupts(struct phy_device *phydev) |
| 866 | { |
Sergei Shtylyov | 553fe92 | 2014-01-05 03:23:19 +0300 | [diff] [blame] | 867 | int err = phy_disable_interrupts(phydev); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 868 | |
| 869 | if (err) |
| 870 | phy_error(phydev); |
| 871 | |
Maciej W. Rozycki | 0ac4952 | 2007-09-28 22:42:14 -0700 | [diff] [blame] | 872 | free_irq(phydev->irq, phydev); |
| 873 | |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 874 | /* If work indeed has been cancelled, disable_irq() will have |
Maciej W. Rozycki | 0ac4952 | 2007-09-28 22:42:14 -0700 | [diff] [blame] | 875 | * been left unbalanced from phy_interrupt() and enable_irq() |
| 876 | * has to be called so that other devices on the line work. |
| 877 | */ |
| 878 | while (atomic_dec_return(&phydev->irq_disable) >= 0) |
| 879 | enable_irq(phydev->irq); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 880 | |
| 881 | return err; |
| 882 | } |
| 883 | EXPORT_SYMBOL(phy_stop_interrupts); |
| 884 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 885 | /** |
Andrew Lunn | 664fcf1 | 2016-10-16 19:56:51 +0200 | [diff] [blame] | 886 | * phy_change - Called by the phy_interrupt to handle PHY changes |
| 887 | * @phydev: phy_device struct that interrupted |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 888 | */ |
Andrew Lunn | 664fcf1 | 2016-10-16 19:56:51 +0200 | [diff] [blame] | 889 | void phy_change(struct phy_device *phydev) |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 890 | { |
Florian Fainelli | deccd16f9 | 2016-01-18 19:33:07 -0800 | [diff] [blame] | 891 | if (phy_interrupt_is_valid(phydev)) { |
| 892 | if (phydev->drv->did_interrupt && |
| 893 | !phydev->drv->did_interrupt(phydev)) |
| 894 | goto ignore; |
Anatolij Gustschin | a8729eb | 2009-04-07 02:01:42 +0000 | [diff] [blame] | 895 | |
Florian Fainelli | deccd16f9 | 2016-01-18 19:33:07 -0800 | [diff] [blame] | 896 | if (phy_disable_interrupts(phydev)) |
| 897 | goto phy_err; |
| 898 | } |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 899 | |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 900 | mutex_lock(&phydev->lock); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 901 | if ((PHY_RUNNING == phydev->state) || (PHY_NOLINK == phydev->state)) |
| 902 | phydev->state = PHY_CHANGELINK; |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 903 | mutex_unlock(&phydev->lock); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 904 | |
Florian Fainelli | deccd16f9 | 2016-01-18 19:33:07 -0800 | [diff] [blame] | 905 | if (phy_interrupt_is_valid(phydev)) { |
| 906 | atomic_dec(&phydev->irq_disable); |
| 907 | enable_irq(phydev->irq); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 908 | |
Florian Fainelli | deccd16f9 | 2016-01-18 19:33:07 -0800 | [diff] [blame] | 909 | /* Reenable interrupts */ |
| 910 | if (PHY_HALTED != phydev->state && |
| 911 | phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED)) |
| 912 | goto irq_enable_err; |
| 913 | } |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 914 | |
Marcin Slusarz | a390d1f | 2009-03-13 15:41:19 -0700 | [diff] [blame] | 915 | /* reschedule state queue work to run as soon as possible */ |
Florian Fainelli | eab1277 | 2017-01-20 15:31:52 -0800 | [diff] [blame] | 916 | phy_trigger_machine(phydev, true); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 917 | return; |
| 918 | |
Anatolij Gustschin | a8729eb | 2009-04-07 02:01:42 +0000 | [diff] [blame] | 919 | ignore: |
| 920 | atomic_dec(&phydev->irq_disable); |
| 921 | enable_irq(phydev->irq); |
| 922 | return; |
| 923 | |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 924 | irq_enable_err: |
| 925 | disable_irq(phydev->irq); |
Maciej W. Rozycki | 0ac4952 | 2007-09-28 22:42:14 -0700 | [diff] [blame] | 926 | atomic_inc(&phydev->irq_disable); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 927 | phy_err: |
| 928 | phy_error(phydev); |
| 929 | } |
| 930 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 931 | /** |
Andrew Lunn | 664fcf1 | 2016-10-16 19:56:51 +0200 | [diff] [blame] | 932 | * phy_change_work - Scheduled by the phy_mac_interrupt to handle PHY changes |
| 933 | * @work: work_struct that describes the work to be done |
| 934 | */ |
| 935 | void phy_change_work(struct work_struct *work) |
| 936 | { |
| 937 | struct phy_device *phydev = |
| 938 | container_of(work, struct phy_device, phy_queue); |
| 939 | |
| 940 | phy_change(phydev); |
| 941 | } |
| 942 | |
| 943 | /** |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 944 | * phy_stop - Bring down the PHY link, and stop checking the status |
| 945 | * @phydev: target phy_device struct |
| 946 | */ |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 947 | void phy_stop(struct phy_device *phydev) |
| 948 | { |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 949 | mutex_lock(&phydev->lock); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 950 | |
| 951 | if (PHY_HALTED == phydev->state) |
| 952 | goto out_unlock; |
| 953 | |
Florian Fainelli | 2c7b492 | 2013-05-19 22:53:42 +0000 | [diff] [blame] | 954 | if (phy_interrupt_is_valid(phydev)) { |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 955 | /* Disable PHY Interrupts */ |
| 956 | phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 957 | |
Maciej W. Rozycki | 3c3070d | 2006-10-03 16:18:35 +0100 | [diff] [blame] | 958 | /* Clear any pending interrupts */ |
| 959 | phy_clear_interrupt(phydev); |
| 960 | } |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 961 | |
Maciej W. Rozycki | 6daf653 | 2007-09-28 22:42:15 -0700 | [diff] [blame] | 962 | phydev->state = PHY_HALTED; |
| 963 | |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 964 | out_unlock: |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 965 | mutex_unlock(&phydev->lock); |
Maciej W. Rozycki | 3c3070d | 2006-10-03 16:18:35 +0100 | [diff] [blame] | 966 | |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 967 | /* Cannot call flush_scheduled_work() here as desired because |
Maciej W. Rozycki | 3c3070d | 2006-10-03 16:18:35 +0100 | [diff] [blame] | 968 | * of rtnl_lock(), but PHY_HALTED shall guarantee phy_change() |
| 969 | * will not reenable interrupts. |
| 970 | */ |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 971 | } |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 972 | EXPORT_SYMBOL(phy_stop); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 973 | |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 974 | /** |
| 975 | * phy_start - start or restart a PHY device |
| 976 | * @phydev: target phy_device struct |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 977 | * |
Randy Dunlap | b3df0da | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 978 | * Description: Indicates the attached device's readiness to |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 979 | * handle PHY-related work. Used during startup to start the |
| 980 | * PHY, and after a call to phy_stop() to resume operation. |
| 981 | * Also used to indicate the MDIO bus has cleared an error |
| 982 | * condition. |
| 983 | */ |
| 984 | void phy_start(struct phy_device *phydev) |
| 985 | { |
Tim Beale | c15e10e | 2015-05-18 15:38:38 +1200 | [diff] [blame] | 986 | bool do_resume = false; |
| 987 | int err = 0; |
| 988 | |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 989 | mutex_lock(&phydev->lock); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 990 | |
| 991 | switch (phydev->state) { |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 992 | case PHY_STARTING: |
| 993 | phydev->state = PHY_PENDING; |
| 994 | break; |
| 995 | case PHY_READY: |
| 996 | phydev->state = PHY_UP; |
| 997 | break; |
| 998 | case PHY_HALTED: |
Tim Beale | c15e10e | 2015-05-18 15:38:38 +1200 | [diff] [blame] | 999 | /* make sure interrupts are re-enabled for the PHY */ |
Shaohui Xie | 84a527a | 2016-05-10 17:42:26 +0800 | [diff] [blame] | 1000 | if (phydev->irq != PHY_POLL) { |
| 1001 | err = phy_enable_interrupts(phydev); |
| 1002 | if (err < 0) |
| 1003 | break; |
| 1004 | } |
Tim Beale | c15e10e | 2015-05-18 15:38:38 +1200 | [diff] [blame] | 1005 | |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1006 | phydev->state = PHY_RESUMING; |
Tim Beale | c15e10e | 2015-05-18 15:38:38 +1200 | [diff] [blame] | 1007 | do_resume = true; |
| 1008 | break; |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1009 | default: |
| 1010 | break; |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 1011 | } |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 1012 | mutex_unlock(&phydev->lock); |
Tim Beale | c15e10e | 2015-05-18 15:38:38 +1200 | [diff] [blame] | 1013 | |
| 1014 | /* if phy was suspended, bring the physical link up again */ |
| 1015 | if (do_resume) |
| 1016 | phy_resume(phydev); |
Andrew Lunn | 3c293f4 | 2016-10-12 22:14:53 +0200 | [diff] [blame] | 1017 | |
Florian Fainelli | eab1277 | 2017-01-20 15:31:52 -0800 | [diff] [blame] | 1018 | phy_trigger_machine(phydev, true); |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 1019 | } |
Andy Fleming | e139345 | 2005-08-24 18:46:21 -0500 | [diff] [blame] | 1020 | EXPORT_SYMBOL(phy_start); |
Jeff Garzik | 67c4f3f | 2005-08-11 02:07:25 -0400 | [diff] [blame] | 1021 | |
Zach Brown | 61a1796 | 2016-10-17 10:49:53 -0500 | [diff] [blame] | 1022 | static void phy_adjust_link(struct phy_device *phydev) |
| 1023 | { |
| 1024 | phydev->adjust_link(phydev->attached_dev); |
Zach Brown | 2e0bc45 | 2016-10-17 10:49:55 -0500 | [diff] [blame] | 1025 | phy_led_trigger_change_speed(phydev); |
Zach Brown | 61a1796 | 2016-10-17 10:49:53 -0500 | [diff] [blame] | 1026 | } |
| 1027 | |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 1028 | /** |
| 1029 | * phy_state_machine - Handle the state machine |
| 1030 | * @work: work_struct that describes the work to be done |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 1031 | */ |
Anton Vorontsov | 4f9c85a | 2010-01-18 05:37:16 +0000 | [diff] [blame] | 1032 | void phy_state_machine(struct work_struct *work) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1033 | { |
Jean Delvare | bf6aede | 2009-04-02 16:56:54 -0700 | [diff] [blame] | 1034 | struct delayed_work *dwork = to_delayed_work(work); |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 1035 | struct phy_device *phydev = |
Marcin Slusarz | a390d1f | 2009-03-13 15:41:19 -0700 | [diff] [blame] | 1036 | container_of(dwork, struct phy_device, state_queue); |
Tim Beale | c15e10e | 2015-05-18 15:38:38 +1200 | [diff] [blame] | 1037 | bool needs_aneg = false, do_suspend = false; |
Florian Fainelli | 3e2186e | 2015-05-16 10:17:56 -0700 | [diff] [blame] | 1038 | enum phy_state old_state; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1039 | int err = 0; |
Shaohui Xie | 11e122c | 2015-08-14 12:23:40 +0800 | [diff] [blame] | 1040 | int old_link; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1041 | |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 1042 | mutex_lock(&phydev->lock); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1043 | |
Florian Fainelli | 3e2186e | 2015-05-16 10:17:56 -0700 | [diff] [blame] | 1044 | old_state = phydev->state; |
| 1045 | |
Florian Fainelli | 25149ef | 2017-02-17 16:07:34 -0800 | [diff] [blame] | 1046 | if (phydev->drv && phydev->drv->link_change_notify) |
Daniel Mack | 2b8f2a2 | 2014-06-18 11:01:41 +0200 | [diff] [blame] | 1047 | phydev->drv->link_change_notify(phydev); |
| 1048 | |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1049 | switch (phydev->state) { |
| 1050 | case PHY_DOWN: |
| 1051 | case PHY_STARTING: |
| 1052 | case PHY_READY: |
| 1053 | case PHY_PENDING: |
| 1054 | break; |
| 1055 | case PHY_UP: |
Zhangfei Gao | 6e14a5ee | 2014-05-15 13:35:34 +0800 | [diff] [blame] | 1056 | needs_aneg = true; |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1057 | |
| 1058 | phydev->link_timeout = PHY_AN_TIMEOUT; |
| 1059 | |
| 1060 | break; |
| 1061 | case PHY_AN: |
| 1062 | err = phy_read_status(phydev); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1063 | if (err < 0) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1064 | break; |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1065 | |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 1066 | /* If the link is down, give up on negotiation for now */ |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1067 | if (!phydev->link) { |
| 1068 | phydev->state = PHY_NOLINK; |
| 1069 | netif_carrier_off(phydev->attached_dev); |
Zach Brown | 61a1796 | 2016-10-17 10:49:53 -0500 | [diff] [blame] | 1070 | phy_adjust_link(phydev); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1071 | break; |
| 1072 | } |
| 1073 | |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 1074 | /* Check if negotiation is done. Break if there's an error */ |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1075 | err = phy_aneg_done(phydev); |
| 1076 | if (err < 0) |
| 1077 | break; |
| 1078 | |
| 1079 | /* If AN is done, we're running */ |
| 1080 | if (err > 0) { |
| 1081 | phydev->state = PHY_RUNNING; |
| 1082 | netif_carrier_on(phydev->attached_dev); |
Zach Brown | 61a1796 | 2016-10-17 10:49:53 -0500 | [diff] [blame] | 1083 | phy_adjust_link(phydev); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1084 | |
Balakumaran Kannan | fa8cdda | 2014-04-09 09:03:45 +0530 | [diff] [blame] | 1085 | } else if (0 == phydev->link_timeout--) |
Zhangfei Gao | 6e14a5ee | 2014-05-15 13:35:34 +0800 | [diff] [blame] | 1086 | needs_aneg = true; |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1087 | break; |
| 1088 | case PHY_NOLINK: |
Andrew Lunn | 321beec | 2015-11-16 23:36:46 +0100 | [diff] [blame] | 1089 | if (phy_interrupt_is_valid(phydev)) |
| 1090 | break; |
| 1091 | |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1092 | err = phy_read_status(phydev); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1093 | if (err) |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1094 | break; |
Andy Fleming | 6b65552 | 2006-10-16 16:19:17 -0500 | [diff] [blame] | 1095 | |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1096 | if (phydev->link) { |
Balakumaran Kannan | e46e08b | 2014-04-24 08:22:47 +0530 | [diff] [blame] | 1097 | if (AUTONEG_ENABLE == phydev->autoneg) { |
| 1098 | err = phy_aneg_done(phydev); |
| 1099 | if (err < 0) |
| 1100 | break; |
| 1101 | |
| 1102 | if (!err) { |
| 1103 | phydev->state = PHY_AN; |
| 1104 | phydev->link_timeout = PHY_AN_TIMEOUT; |
| 1105 | break; |
| 1106 | } |
| 1107 | } |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1108 | phydev->state = PHY_RUNNING; |
| 1109 | netif_carrier_on(phydev->attached_dev); |
Zach Brown | 61a1796 | 2016-10-17 10:49:53 -0500 | [diff] [blame] | 1110 | phy_adjust_link(phydev); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1111 | } |
| 1112 | break; |
| 1113 | case PHY_FORCING: |
| 1114 | err = genphy_update_link(phydev); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1115 | if (err) |
| 1116 | break; |
Andy Fleming | 6b65552 | 2006-10-16 16:19:17 -0500 | [diff] [blame] | 1117 | |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1118 | if (phydev->link) { |
| 1119 | phydev->state = PHY_RUNNING; |
| 1120 | netif_carrier_on(phydev->attached_dev); |
| 1121 | } else { |
| 1122 | if (0 == phydev->link_timeout--) |
Zhangfei Gao | 6e14a5ee | 2014-05-15 13:35:34 +0800 | [diff] [blame] | 1123 | needs_aneg = true; |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1124 | } |
| 1125 | |
Zach Brown | 61a1796 | 2016-10-17 10:49:53 -0500 | [diff] [blame] | 1126 | phy_adjust_link(phydev); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1127 | break; |
| 1128 | case PHY_RUNNING: |
Florian Fainelli | d5c3d84 | 2016-01-18 19:33:06 -0800 | [diff] [blame] | 1129 | /* Only register a CHANGE if we are polling and link changed |
| 1130 | * since latest checking. |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1131 | */ |
Florian Fainelli | d5c3d84 | 2016-01-18 19:33:06 -0800 | [diff] [blame] | 1132 | if (phydev->irq == PHY_POLL) { |
Shaohui Xie | 11e122c | 2015-08-14 12:23:40 +0800 | [diff] [blame] | 1133 | old_link = phydev->link; |
| 1134 | err = phy_read_status(phydev); |
| 1135 | if (err) |
| 1136 | break; |
| 1137 | |
| 1138 | if (old_link != phydev->link) |
| 1139 | phydev->state = PHY_CHANGELINK; |
| 1140 | } |
Zefir Kurtisi | 811a919 | 2017-01-06 12:14:48 +0100 | [diff] [blame] | 1141 | /* |
| 1142 | * Failsafe: check that nobody set phydev->link=0 between two |
| 1143 | * poll cycles, otherwise we won't leave RUNNING state as long |
| 1144 | * as link remains down. |
| 1145 | */ |
| 1146 | if (!phydev->link && phydev->state == PHY_RUNNING) { |
| 1147 | phydev->state = PHY_CHANGELINK; |
| 1148 | phydev_err(phydev, "no link in PHY_RUNNING\n"); |
| 1149 | } |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1150 | break; |
| 1151 | case PHY_CHANGELINK: |
| 1152 | err = phy_read_status(phydev); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1153 | if (err) |
| 1154 | break; |
| 1155 | |
| 1156 | if (phydev->link) { |
| 1157 | phydev->state = PHY_RUNNING; |
| 1158 | netif_carrier_on(phydev->attached_dev); |
| 1159 | } else { |
| 1160 | phydev->state = PHY_NOLINK; |
| 1161 | netif_carrier_off(phydev->attached_dev); |
| 1162 | } |
| 1163 | |
Zach Brown | 61a1796 | 2016-10-17 10:49:53 -0500 | [diff] [blame] | 1164 | phy_adjust_link(phydev); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1165 | |
| 1166 | if (phy_interrupt_is_valid(phydev)) |
| 1167 | err = phy_config_interrupt(phydev, |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 1168 | PHY_INTERRUPT_ENABLED); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1169 | break; |
| 1170 | case PHY_HALTED: |
| 1171 | if (phydev->link) { |
| 1172 | phydev->link = 0; |
| 1173 | netif_carrier_off(phydev->attached_dev); |
Zach Brown | 61a1796 | 2016-10-17 10:49:53 -0500 | [diff] [blame] | 1174 | phy_adjust_link(phydev); |
Zhangfei Gao | 6e14a5ee | 2014-05-15 13:35:34 +0800 | [diff] [blame] | 1175 | do_suspend = true; |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1176 | } |
| 1177 | break; |
| 1178 | case PHY_RESUMING: |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1179 | if (AUTONEG_ENABLE == phydev->autoneg) { |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1180 | err = phy_aneg_done(phydev); |
| 1181 | if (err < 0) |
| 1182 | break; |
| 1183 | |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1184 | /* err > 0 if AN is done. |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 1185 | * Otherwise, it's 0, and we're still waiting for AN |
| 1186 | */ |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1187 | if (err > 0) { |
Wade Farnsworth | 42caa07 | 2009-07-01 13:00:34 +0000 | [diff] [blame] | 1188 | err = phy_read_status(phydev); |
| 1189 | if (err) |
| 1190 | break; |
| 1191 | |
| 1192 | if (phydev->link) { |
| 1193 | phydev->state = PHY_RUNNING; |
| 1194 | netif_carrier_on(phydev->attached_dev); |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 1195 | } else { |
Wade Farnsworth | 42caa07 | 2009-07-01 13:00:34 +0000 | [diff] [blame] | 1196 | phydev->state = PHY_NOLINK; |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 1197 | } |
Zach Brown | 61a1796 | 2016-10-17 10:49:53 -0500 | [diff] [blame] | 1198 | phy_adjust_link(phydev); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1199 | } else { |
| 1200 | phydev->state = PHY_AN; |
| 1201 | phydev->link_timeout = PHY_AN_TIMEOUT; |
Wade Farnsworth | 42caa07 | 2009-07-01 13:00:34 +0000 | [diff] [blame] | 1202 | } |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1203 | } else { |
| 1204 | err = phy_read_status(phydev); |
| 1205 | if (err) |
| 1206 | break; |
| 1207 | |
| 1208 | if (phydev->link) { |
| 1209 | phydev->state = PHY_RUNNING; |
| 1210 | netif_carrier_on(phydev->attached_dev); |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 1211 | } else { |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1212 | phydev->state = PHY_NOLINK; |
Sergei Shtylyov | 2f53e90 | 2014-01-05 03:17:06 +0300 | [diff] [blame] | 1213 | } |
Zach Brown | 61a1796 | 2016-10-17 10:49:53 -0500 | [diff] [blame] | 1214 | phy_adjust_link(phydev); |
Florian Fainelli | e109374 | 2013-12-17 21:38:12 -0800 | [diff] [blame] | 1215 | } |
| 1216 | break; |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1217 | } |
| 1218 | |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 1219 | mutex_unlock(&phydev->lock); |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1220 | |
| 1221 | if (needs_aneg) |
Alexander Kochetkov | f555f34 | 2017-04-20 14:00:04 +0300 | [diff] [blame] | 1222 | err = phy_start_aneg_priv(phydev, false); |
Zhangfei Gao | 6e14a5ee | 2014-05-15 13:35:34 +0800 | [diff] [blame] | 1223 | else if (do_suspend) |
Sebastian Hesselbarth | be9dad1 | 2013-12-13 10:20:29 +0100 | [diff] [blame] | 1224 | phy_suspend(phydev); |
| 1225 | |
Andy Fleming | 00db818 | 2005-07-30 19:31:23 -0400 | [diff] [blame] | 1226 | if (err < 0) |
| 1227 | phy_error(phydev); |
| 1228 | |
Andrew Lunn | 72ba48b | 2016-01-06 20:11:09 +0100 | [diff] [blame] | 1229 | phydev_dbg(phydev, "PHY state change %s -> %s\n", |
| 1230 | phy_state_to_str(old_state), |
| 1231 | phy_state_to_str(phydev->state)); |
Florian Fainelli | 3e2186e | 2015-05-16 10:17:56 -0700 | [diff] [blame] | 1232 | |
Florian Fainelli | d5c3d84 | 2016-01-18 19:33:06 -0800 | [diff] [blame] | 1233 | /* Only re-schedule a PHY state machine change if we are polling the |
| 1234 | * PHY, if PHY_IGNORE_INTERRUPT is set, then we will be moving |
| 1235 | * between states from phy_mac_interrupt() |
| 1236 | */ |
| 1237 | if (phydev->irq == PHY_POLL) |
| 1238 | queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, |
| 1239 | PHY_STATE_TIME * HZ); |
Nate Case | 35b5f6b | 2008-01-29 10:05:09 -0600 | [diff] [blame] | 1240 | } |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1241 | |
Andrew Lunn | 664fcf1 | 2016-10-16 19:56:51 +0200 | [diff] [blame] | 1242 | /** |
| 1243 | * phy_mac_interrupt - MAC says the link has changed |
| 1244 | * @phydev: phy_device struct with changed link |
| 1245 | * @new_link: Link is Up/Down. |
| 1246 | * |
| 1247 | * Description: The MAC layer is able indicate there has been a change |
| 1248 | * in the PHY link status. Set the new link status, and trigger the |
| 1249 | * state machine, work a work queue. |
| 1250 | */ |
Florian Fainelli | 5ea94e7 | 2013-05-19 22:53:43 +0000 | [diff] [blame] | 1251 | void phy_mac_interrupt(struct phy_device *phydev, int new_link) |
| 1252 | { |
Florian Fainelli | 5ea94e7 | 2013-05-19 22:53:43 +0000 | [diff] [blame] | 1253 | phydev->link = new_link; |
Florian Fainelli | deccd16f9 | 2016-01-18 19:33:07 -0800 | [diff] [blame] | 1254 | |
| 1255 | /* Trigger a state machine change */ |
| 1256 | queue_work(system_power_efficient_wq, &phydev->phy_queue); |
Florian Fainelli | 5ea94e7 | 2013-05-19 22:53:43 +0000 | [diff] [blame] | 1257 | } |
| 1258 | EXPORT_SYMBOL(phy_mac_interrupt); |
| 1259 | |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1260 | /** |
| 1261 | * phy_init_eee - init and check the EEE feature |
| 1262 | * @phydev: target phy_device struct |
| 1263 | * @clk_stop_enable: PHY may stop the clock during LPI |
| 1264 | * |
| 1265 | * Description: it checks if the Energy-Efficient Ethernet (EEE) |
| 1266 | * is supported by looking at the MMD registers 3.20 and 7.60/61 |
| 1267 | * and it programs the MMD register 3.0 setting the "Clock stop enable" |
| 1268 | * bit if required. |
| 1269 | */ |
| 1270 | int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable) |
| 1271 | { |
Florian Fainelli | 25149ef | 2017-02-17 16:07:34 -0800 | [diff] [blame] | 1272 | if (!phydev->drv) |
| 1273 | return -EIO; |
| 1274 | |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1275 | /* According to 802.3az,the EEE is supported only in full duplex-mode. |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1276 | */ |
Russell King | 32d7514 | 2017-03-31 10:37:18 +0100 | [diff] [blame] | 1277 | if (phydev->duplex == DUPLEX_FULL) { |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1278 | int eee_lp, eee_cap, eee_adv; |
| 1279 | u32 lp, cap, adv; |
Bjorn Helgaas | 4ae6e50 | 2014-03-04 17:35:44 -0700 | [diff] [blame] | 1280 | int status; |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1281 | |
| 1282 | /* Read phy status to properly get the right settings */ |
| 1283 | status = phy_read_status(phydev); |
| 1284 | if (status) |
| 1285 | return status; |
| 1286 | |
| 1287 | /* First check if the EEE ability is supported */ |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 1288 | eee_cap = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE); |
Giuseppe CAVALLARO | 7a4cecf | 2014-08-26 09:26:52 +0200 | [diff] [blame] | 1289 | if (eee_cap <= 0) |
| 1290 | goto eee_exit_err; |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1291 | |
Allan, Bruce W | b32607d | 2012-08-20 04:55:29 +0000 | [diff] [blame] | 1292 | cap = mmd_eee_cap_to_ethtool_sup_t(eee_cap); |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1293 | if (!cap) |
Giuseppe CAVALLARO | 7a4cecf | 2014-08-26 09:26:52 +0200 | [diff] [blame] | 1294 | goto eee_exit_err; |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1295 | |
| 1296 | /* Check which link settings negotiated and verify it in |
| 1297 | * the EEE advertising registers. |
| 1298 | */ |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 1299 | eee_lp = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_LPABLE); |
Giuseppe CAVALLARO | 7a4cecf | 2014-08-26 09:26:52 +0200 | [diff] [blame] | 1300 | if (eee_lp <= 0) |
| 1301 | goto eee_exit_err; |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1302 | |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 1303 | eee_adv = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV); |
Giuseppe CAVALLARO | 7a4cecf | 2014-08-26 09:26:52 +0200 | [diff] [blame] | 1304 | if (eee_adv <= 0) |
| 1305 | goto eee_exit_err; |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1306 | |
Allan, Bruce W | b32607d | 2012-08-20 04:55:29 +0000 | [diff] [blame] | 1307 | adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv); |
| 1308 | lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp); |
Guenter Roeck | 54da5a8 | 2015-02-17 09:36:22 -0800 | [diff] [blame] | 1309 | if (!phy_check_valid(phydev->speed, phydev->duplex, lp & adv)) |
Giuseppe CAVALLARO | 7a4cecf | 2014-08-26 09:26:52 +0200 | [diff] [blame] | 1310 | goto eee_exit_err; |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1311 | |
| 1312 | if (clk_stop_enable) { |
| 1313 | /* Configure the PHY to stop receiving xMII |
| 1314 | * clock while it is signaling LPI. |
| 1315 | */ |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 1316 | int val = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1); |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1317 | if (val < 0) |
| 1318 | return val; |
| 1319 | |
| 1320 | val |= MDIO_PCS_CTRL1_CLKSTOP_EN; |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 1321 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, val); |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
Sergei Shtylyov | e62a768 | 2014-01-05 03:21:52 +0300 | [diff] [blame] | 1324 | return 0; /* EEE supported */ |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1325 | } |
Giuseppe CAVALLARO | 7a4cecf | 2014-08-26 09:26:52 +0200 | [diff] [blame] | 1326 | eee_exit_err: |
Sergei Shtylyov | e62a768 | 2014-01-05 03:21:52 +0300 | [diff] [blame] | 1327 | return -EPROTONOSUPPORT; |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1328 | } |
| 1329 | EXPORT_SYMBOL(phy_init_eee); |
| 1330 | |
| 1331 | /** |
| 1332 | * phy_get_eee_err - report the EEE wake error count |
| 1333 | * @phydev: target phy_device struct |
| 1334 | * |
| 1335 | * Description: it is to report the number of time where the PHY |
| 1336 | * failed to complete its normal wake sequence. |
| 1337 | */ |
| 1338 | int phy_get_eee_err(struct phy_device *phydev) |
| 1339 | { |
Florian Fainelli | 25149ef | 2017-02-17 16:07:34 -0800 | [diff] [blame] | 1340 | if (!phydev->drv) |
| 1341 | return -EIO; |
| 1342 | |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 1343 | return phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_EEE_WK_ERR); |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1344 | } |
| 1345 | EXPORT_SYMBOL(phy_get_eee_err); |
| 1346 | |
| 1347 | /** |
| 1348 | * phy_ethtool_get_eee - get EEE supported and status |
| 1349 | * @phydev: target phy_device struct |
| 1350 | * @data: ethtool_eee data |
| 1351 | * |
| 1352 | * Description: it reportes the Supported/Advertisement/LP Advertisement |
| 1353 | * capabilities. |
| 1354 | */ |
| 1355 | int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data) |
| 1356 | { |
| 1357 | int val; |
| 1358 | |
Florian Fainelli | 25149ef | 2017-02-17 16:07:34 -0800 | [diff] [blame] | 1359 | if (!phydev->drv) |
| 1360 | return -EIO; |
| 1361 | |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1362 | /* Get Supported EEE */ |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 1363 | val = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE); |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1364 | if (val < 0) |
| 1365 | return val; |
Allan, Bruce W | b32607d | 2012-08-20 04:55:29 +0000 | [diff] [blame] | 1366 | data->supported = mmd_eee_cap_to_ethtool_sup_t(val); |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1367 | |
| 1368 | /* Get advertisement EEE */ |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 1369 | val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV); |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1370 | if (val < 0) |
| 1371 | return val; |
Allan, Bruce W | b32607d | 2012-08-20 04:55:29 +0000 | [diff] [blame] | 1372 | data->advertised = mmd_eee_adv_to_ethtool_adv_t(val); |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1373 | |
| 1374 | /* Get LP advertisement EEE */ |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 1375 | val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_LPABLE); |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1376 | if (val < 0) |
| 1377 | return val; |
Allan, Bruce W | b32607d | 2012-08-20 04:55:29 +0000 | [diff] [blame] | 1378 | data->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(val); |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1379 | |
| 1380 | return 0; |
| 1381 | } |
| 1382 | EXPORT_SYMBOL(phy_ethtool_get_eee); |
| 1383 | |
| 1384 | /** |
| 1385 | * phy_ethtool_set_eee - set EEE supported and status |
| 1386 | * @phydev: target phy_device struct |
| 1387 | * @data: ethtool_eee data |
| 1388 | * |
| 1389 | * Description: it is to program the Advertisement EEE register. |
| 1390 | */ |
| 1391 | int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data) |
| 1392 | { |
Russell King | f75abeb | 2017-03-31 10:37:12 +0100 | [diff] [blame] | 1393 | int cap, old_adv, adv, ret; |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1394 | |
Florian Fainelli | 25149ef | 2017-02-17 16:07:34 -0800 | [diff] [blame] | 1395 | if (!phydev->drv) |
| 1396 | return -EIO; |
| 1397 | |
Russell King | 83ea067 | 2017-03-31 10:37:07 +0100 | [diff] [blame] | 1398 | /* Get Supported EEE */ |
| 1399 | cap = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE); |
| 1400 | if (cap < 0) |
| 1401 | return cap; |
| 1402 | |
Russell King | f75abeb | 2017-03-31 10:37:12 +0100 | [diff] [blame] | 1403 | old_adv = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV); |
| 1404 | if (old_adv < 0) |
| 1405 | return old_adv; |
| 1406 | |
Russell King | 83ea067 | 2017-03-31 10:37:07 +0100 | [diff] [blame] | 1407 | adv = ethtool_adv_to_mmd_eee_adv_t(data->advertised) & cap; |
| 1408 | |
jbrunet | d853d14 | 2016-11-28 10:46:46 +0100 | [diff] [blame] | 1409 | /* Mask prohibited EEE modes */ |
Russell King | 83ea067 | 2017-03-31 10:37:07 +0100 | [diff] [blame] | 1410 | adv &= ~phydev->eee_broken_modes; |
jbrunet | d853d14 | 2016-11-28 10:46:46 +0100 | [diff] [blame] | 1411 | |
Russell King | f75abeb | 2017-03-31 10:37:12 +0100 | [diff] [blame] | 1412 | if (old_adv != adv) { |
| 1413 | ret = phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, adv); |
| 1414 | if (ret < 0) |
| 1415 | return ret; |
| 1416 | |
| 1417 | /* Restart autonegotiation so the new modes get sent to the |
| 1418 | * link partner. |
| 1419 | */ |
| 1420 | ret = genphy_restart_aneg(phydev); |
| 1421 | if (ret < 0) |
| 1422 | return ret; |
| 1423 | } |
| 1424 | |
| 1425 | return 0; |
Giuseppe CAVALLARO | a59a4d1 | 2012-06-27 21:14:38 +0000 | [diff] [blame] | 1426 | } |
| 1427 | EXPORT_SYMBOL(phy_ethtool_set_eee); |
Michael Stapelberg | 42e836e | 2013-03-11 13:56:44 +0000 | [diff] [blame] | 1428 | |
| 1429 | int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) |
| 1430 | { |
Florian Fainelli | 25149ef | 2017-02-17 16:07:34 -0800 | [diff] [blame] | 1431 | if (phydev->drv && phydev->drv->set_wol) |
Michael Stapelberg | 42e836e | 2013-03-11 13:56:44 +0000 | [diff] [blame] | 1432 | return phydev->drv->set_wol(phydev, wol); |
| 1433 | |
| 1434 | return -EOPNOTSUPP; |
| 1435 | } |
| 1436 | EXPORT_SYMBOL(phy_ethtool_set_wol); |
| 1437 | |
| 1438 | void phy_ethtool_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) |
| 1439 | { |
Florian Fainelli | 25149ef | 2017-02-17 16:07:34 -0800 | [diff] [blame] | 1440 | if (phydev->drv && phydev->drv->get_wol) |
Michael Stapelberg | 42e836e | 2013-03-11 13:56:44 +0000 | [diff] [blame] | 1441 | phydev->drv->get_wol(phydev, wol); |
| 1442 | } |
| 1443 | EXPORT_SYMBOL(phy_ethtool_get_wol); |
Philippe Reynes | 9d9a77c | 2016-05-10 00:19:41 +0200 | [diff] [blame] | 1444 | |
| 1445 | int phy_ethtool_get_link_ksettings(struct net_device *ndev, |
| 1446 | struct ethtool_link_ksettings *cmd) |
| 1447 | { |
| 1448 | struct phy_device *phydev = ndev->phydev; |
| 1449 | |
| 1450 | if (!phydev) |
| 1451 | return -ENODEV; |
| 1452 | |
| 1453 | return phy_ethtool_ksettings_get(phydev, cmd); |
| 1454 | } |
| 1455 | EXPORT_SYMBOL(phy_ethtool_get_link_ksettings); |
| 1456 | |
| 1457 | int phy_ethtool_set_link_ksettings(struct net_device *ndev, |
| 1458 | const struct ethtool_link_ksettings *cmd) |
| 1459 | { |
| 1460 | struct phy_device *phydev = ndev->phydev; |
| 1461 | |
| 1462 | if (!phydev) |
| 1463 | return -ENODEV; |
| 1464 | |
| 1465 | return phy_ethtool_ksettings_set(phydev, cmd); |
| 1466 | } |
| 1467 | EXPORT_SYMBOL(phy_ethtool_set_link_ksettings); |
Florian Fainelli | e86a898 | 2016-11-15 10:06:30 -0800 | [diff] [blame] | 1468 | |
| 1469 | int phy_ethtool_nway_reset(struct net_device *ndev) |
| 1470 | { |
| 1471 | struct phy_device *phydev = ndev->phydev; |
| 1472 | |
| 1473 | if (!phydev) |
| 1474 | return -ENODEV; |
| 1475 | |
Florian Fainelli | 25149ef | 2017-02-17 16:07:34 -0800 | [diff] [blame] | 1476 | if (!phydev->drv) |
| 1477 | return -EIO; |
| 1478 | |
Florian Fainelli | e86a898 | 2016-11-15 10:06:30 -0800 | [diff] [blame] | 1479 | return genphy_restart_aneg(phydev); |
| 1480 | } |
| 1481 | EXPORT_SYMBOL(phy_ethtool_nway_reset); |