blob: ee411b0eef5d3207e36c7874bb80cecf8747e1cf [file] [log] [blame]
Andy Fleming00db8182005-07-30 19:31:23 -04001/*
2 * include/linux/phy.h
3 *
4 * Framework and drivers for configuring and reading different PHYs
5 * Based on code in sungem_phy.c and gianfar_phy.c
6 *
7 * Author: Andy Fleming
8 *
9 * Copyright (c) 2004 Freescale Semiconductor, Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 */
17
18#ifndef __PHY_H
19#define __PHY_H
20
21#include <linux/spinlock.h>
Maciej W. Rozycki13df29f2006-10-03 16:18:28 +010022#include <linux/ethtool.h>
23#include <linux/mii.h>
24#include <linux/timer.h>
25#include <linux/workqueue.h>
David Woodhouse8626d3b2010-04-02 01:05:27 +000026#include <linux/mod_devicetable.h>
Andy Fleming00db8182005-07-30 19:31:23 -040027
Arun Sharma600634972011-07-26 16:09:06 -070028#include <linux/atomic.h>
Maciej W. Rozycki0ac49522007-09-28 22:42:14 -070029
Andy Fleming00db8182005-07-30 19:31:23 -040030#define PHY_BASIC_FEATURES (SUPPORTED_10baseT_Half | \
31 SUPPORTED_10baseT_Full | \
32 SUPPORTED_100baseT_Half | \
33 SUPPORTED_100baseT_Full | \
34 SUPPORTED_Autoneg | \
35 SUPPORTED_TP | \
36 SUPPORTED_MII)
37
38#define PHY_GBIT_FEATURES (PHY_BASIC_FEATURES | \
39 SUPPORTED_1000baseT_Half | \
40 SUPPORTED_1000baseT_Full)
41
Andy Flemingc5e38a92008-04-09 19:38:27 -050042/*
43 * Set phydev->irq to PHY_POLL if interrupts are not supported,
Andy Fleming00db8182005-07-30 19:31:23 -040044 * or not desired for this PHY. Set to PHY_IGNORE_INTERRUPT if
45 * the attached driver handles the interrupt
46 */
47#define PHY_POLL -1
48#define PHY_IGNORE_INTERRUPT -2
49
50#define PHY_HAS_INTERRUPT 0x00000001
51#define PHY_HAS_MAGICANEG 0x00000002
Florian Fainelli4284b6a2013-05-23 01:11:12 +000052#define PHY_IS_INTERNAL 0x00000004
Andy Fleming00db8182005-07-30 19:31:23 -040053
Andy Fleminge8a2b6a2006-12-01 12:01:06 -060054/* Interface Mode definitions */
55typedef enum {
Shawn Guo4157ef12011-07-05 16:42:09 +080056 PHY_INTERFACE_MODE_NA,
Andy Fleminge8a2b6a2006-12-01 12:01:06 -060057 PHY_INTERFACE_MODE_MII,
58 PHY_INTERFACE_MODE_GMII,
59 PHY_INTERFACE_MODE_SGMII,
60 PHY_INTERFACE_MODE_TBI,
61 PHY_INTERFACE_MODE_RMII,
62 PHY_INTERFACE_MODE_RGMII,
Kim Phillipsa9995892007-04-13 01:25:57 -050063 PHY_INTERFACE_MODE_RGMII_ID,
Kim Phillips7d400a42007-11-26 16:17:48 -060064 PHY_INTERFACE_MODE_RGMII_RXID,
65 PHY_INTERFACE_MODE_RGMII_TXID,
Shawn Guo4157ef12011-07-05 16:42:09 +080066 PHY_INTERFACE_MODE_RTBI,
67 PHY_INTERFACE_MODE_SMII,
Andy Fleminge8a2b6a2006-12-01 12:01:06 -060068} phy_interface_t;
69
Andy Fleming00db8182005-07-30 19:31:23 -040070
Andy Fleminge8a2b6a2006-12-01 12:01:06 -060071#define PHY_INIT_TIMEOUT 100000
Andy Fleming00db8182005-07-30 19:31:23 -040072#define PHY_STATE_TIME 1
73#define PHY_FORCE_TIMEOUT 10
74#define PHY_AN_TIMEOUT 10
75
Andy Fleminge8a2b6a2006-12-01 12:01:06 -060076#define PHY_MAX_ADDR 32
Andy Fleming00db8182005-07-30 19:31:23 -040077
Kumar Galaa4d00f12006-01-11 11:27:33 -080078/* Used when trying to connect to a specific phy (mii bus id:phy device id) */
Andy Fleming9d9326d2008-04-09 19:38:13 -050079#define PHY_ID_FMT "%s:%02x"
80
81/*
82 * Need to be a little smaller than phydev->dev.bus_id to leave room
83 * for the ":%02x"
84 */
David S. Miller8e401ec2009-05-26 21:16:25 -070085#define MII_BUS_ID_SIZE (20 - 3)
Kumar Galaa4d00f12006-01-11 11:27:33 -080086
Jason Gunthorpeabf35df2010-03-09 09:17:42 +000087/* Or MII_ADDR_C45 into regnum for read/write on mii_bus to enable the 21 bit
88 IEEE 802.3ae clause 45 addressing mode used by 10GIGE phy chips. */
89#define MII_ADDR_C45 (1<<30)
90
Paul Gortmaker313162d2012-01-30 11:46:54 -050091struct device;
92struct sk_buff;
93
Andy Flemingc5e38a92008-04-09 19:38:27 -050094/*
95 * The Bus class for PHYs. Devices which provide access to
96 * PHYs should register using this structure
97 */
Andy Fleming00db8182005-07-30 19:31:23 -040098struct mii_bus {
99 const char *name;
Andy Fleming9d9326d2008-04-09 19:38:13 -0500100 char id[MII_BUS_ID_SIZE];
Andy Fleming00db8182005-07-30 19:31:23 -0400101 void *priv;
102 int (*read)(struct mii_bus *bus, int phy_id, int regnum);
103 int (*write)(struct mii_bus *bus, int phy_id, int regnum, u16 val);
104 int (*reset)(struct mii_bus *bus);
105
Andy Flemingc5e38a92008-04-09 19:38:27 -0500106 /*
107 * A lock to ensure that only one thing can read/write
108 * the MDIO bus at a time
109 */
Nate Case35b5f6b2008-01-29 10:05:09 -0600110 struct mutex mdio_lock;
Andy Fleming00db8182005-07-30 19:31:23 -0400111
Lennert Buytenhek18ee49d2008-10-01 15:41:33 +0000112 struct device *parent;
Lennert Buytenhek46abc022008-10-08 16:33:40 -0700113 enum {
114 MDIOBUS_ALLOCATED = 1,
115 MDIOBUS_REGISTERED,
116 MDIOBUS_UNREGISTERED,
117 MDIOBUS_RELEASED,
118 } state;
119 struct device dev;
Andy Fleming00db8182005-07-30 19:31:23 -0400120
121 /* list of all PHYs on bus */
122 struct phy_device *phy_map[PHY_MAX_ADDR];
123
Peter Meerwaldc6883992010-09-02 04:06:24 +0000124 /* PHY addresses to be ignored when probing */
Matt Porterf896424c2005-11-02 16:13:06 -0700125 u32 phy_mask;
126
Andy Flemingc5e38a92008-04-09 19:38:27 -0500127 /*
128 * Pointer to an array of interrupts, each PHY's
129 * interrupt at the index matching its address
130 */
Andy Fleming00db8182005-07-30 19:31:23 -0400131 int *irq;
132};
Lennert Buytenhek46abc022008-10-08 16:33:40 -0700133#define to_mii_bus(d) container_of(d, struct mii_bus, dev)
Andy Fleming00db8182005-07-30 19:31:23 -0400134
Timur Tabieb8a54a72012-01-12 15:23:04 -0800135struct mii_bus *mdiobus_alloc_size(size_t);
136static inline struct mii_bus *mdiobus_alloc(void)
137{
138 return mdiobus_alloc_size(0);
139}
140
Lennert Buytenhek2e888102008-09-29 17:12:35 +0000141int mdiobus_register(struct mii_bus *bus);
142void mdiobus_unregister(struct mii_bus *bus);
143void mdiobus_free(struct mii_bus *bus);
144struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
Jason Gunthorpeabf35df2010-03-09 09:17:42 +0000145int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
146int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
Lennert Buytenhek2e888102008-09-29 17:12:35 +0000147
148
Andy Fleminge8a2b6a2006-12-01 12:01:06 -0600149#define PHY_INTERRUPT_DISABLED 0x0
150#define PHY_INTERRUPT_ENABLED 0x80000000
Andy Fleming00db8182005-07-30 19:31:23 -0400151
152/* PHY state machine states:
153 *
154 * DOWN: PHY device and driver are not ready for anything. probe
155 * should be called if and only if the PHY is in this state,
156 * given that the PHY device exists.
157 * - PHY driver probe function will, depending on the PHY, set
158 * the state to STARTING or READY
159 *
160 * STARTING: PHY device is coming up, and the ethernet driver is
161 * not ready. PHY drivers may set this in the probe function.
162 * If they do, they are responsible for making sure the state is
163 * eventually set to indicate whether the PHY is UP or READY,
164 * depending on the state when the PHY is done starting up.
165 * - PHY driver will set the state to READY
166 * - start will set the state to PENDING
167 *
168 * READY: PHY is ready to send and receive packets, but the
169 * controller is not. By default, PHYs which do not implement
170 * probe will be set to this state by phy_probe(). If the PHY
171 * driver knows the PHY is ready, and the PHY state is STARTING,
172 * then it sets this STATE.
173 * - start will set the state to UP
174 *
175 * PENDING: PHY device is coming up, but the ethernet driver is
176 * ready. phy_start will set this state if the PHY state is
177 * STARTING.
178 * - PHY driver will set the state to UP when the PHY is ready
179 *
180 * UP: The PHY and attached device are ready to do work.
181 * Interrupts should be started here.
182 * - timer moves to AN
183 *
184 * AN: The PHY is currently negotiating the link state. Link is
185 * therefore down for now. phy_timer will set this state when it
186 * detects the state is UP. config_aneg will set this state
187 * whenever called with phydev->autoneg set to AUTONEG_ENABLE.
188 * - If autonegotiation finishes, but there's no link, it sets
189 * the state to NOLINK.
190 * - If aneg finishes with link, it sets the state to RUNNING,
191 * and calls adjust_link
192 * - If autonegotiation did not finish after an arbitrary amount
193 * of time, autonegotiation should be tried again if the PHY
194 * supports "magic" autonegotiation (back to AN)
195 * - If it didn't finish, and no magic_aneg, move to FORCING.
196 *
197 * NOLINK: PHY is up, but not currently plugged in.
198 * - If the timer notes that the link comes back, we move to RUNNING
199 * - config_aneg moves to AN
200 * - phy_stop moves to HALTED
201 *
202 * FORCING: PHY is being configured with forced settings
203 * - if link is up, move to RUNNING
204 * - If link is down, we drop to the next highest setting, and
205 * retry (FORCING) after a timeout
206 * - phy_stop moves to HALTED
207 *
208 * RUNNING: PHY is currently up, running, and possibly sending
209 * and/or receiving packets
210 * - timer will set CHANGELINK if we're polling (this ensures the
211 * link state is polled every other cycle of this state machine,
212 * which makes it every other second)
213 * - irq will set CHANGELINK
214 * - config_aneg will set AN
215 * - phy_stop moves to HALTED
216 *
217 * CHANGELINK: PHY experienced a change in link state
218 * - timer moves to RUNNING if link
219 * - timer moves to NOLINK if the link is down
220 * - phy_stop moves to HALTED
221 *
222 * HALTED: PHY is up, but no polling or interrupts are done. Or
223 * PHY is in an error state.
224 *
225 * - phy_start moves to RESUMING
226 *
227 * RESUMING: PHY was halted, but now wants to run again.
228 * - If we are forcing, or aneg is done, timer moves to RUNNING
229 * - If aneg is not done, timer moves to AN
230 * - phy_stop moves to HALTED
231 */
232enum phy_state {
233 PHY_DOWN=0,
234 PHY_STARTING,
235 PHY_READY,
236 PHY_PENDING,
237 PHY_UP,
238 PHY_AN,
239 PHY_RUNNING,
240 PHY_NOLINK,
241 PHY_FORCING,
242 PHY_CHANGELINK,
243 PHY_HALTED,
244 PHY_RESUMING
245};
246
David Daneyac28b9f2012-06-27 07:33:35 +0000247/**
248 * struct phy_c45_device_ids - 802.3-c45 Device Identifiers
249 * @devices_in_package: Bit vector of devices present.
250 * @device_ids: The device identifer for each present device.
251 */
252struct phy_c45_device_ids {
253 u32 devices_in_package;
254 u32 device_ids[8];
255};
Richard Cochranc1f19b52010-07-17 08:49:36 +0000256
Andy Fleming00db8182005-07-30 19:31:23 -0400257/* phy_device: An instance of a PHY
258 *
259 * drv: Pointer to the driver for this PHY instance
260 * bus: Pointer to the bus this PHY is on
261 * dev: driver model device structure for this PHY
262 * phy_id: UID for this device found during discovery
David Daneyac28b9f2012-06-27 07:33:35 +0000263 * c45_ids: 802.3-c45 Device Identifers if is_c45.
264 * is_c45: Set to true if this phy uses clause 45 addressing.
Florian Fainelli4284b6a2013-05-23 01:11:12 +0000265 * is_internal: Set to true if this phy is internal to a MAC.
Andy Fleming00db8182005-07-30 19:31:23 -0400266 * state: state of the PHY for management purposes
267 * dev_flags: Device-specific flags used by the PHY driver.
268 * addr: Bus address of PHY
269 * link_timeout: The number of timer firings to wait before the
270 * giving up on the current attempt at acquiring a link
271 * irq: IRQ number of the PHY's interrupt (-1 if none)
272 * phy_timer: The timer for handling the state machine
273 * phy_queue: A work_queue for the interrupt
274 * attached_dev: The attached enet driver's device instance ptr
275 * adjust_link: Callback for the enet controller to respond to
276 * changes in the link state.
277 * adjust_state: Callback for the enet driver to respond to
278 * changes in the state machine.
279 *
280 * speed, duplex, pause, supported, advertising, and
281 * autoneg are used like in mii_if_info
282 *
283 * interrupts currently only supports enabled or disabled,
284 * but could be changed in the future to support enabling
285 * and disabling specific interrupts
286 *
287 * Contains some infrastructure for polling and interrupt
288 * handling, as well as handling shifts in PHY hardware state
289 */
290struct phy_device {
291 /* Information about the PHY type */
292 /* And management functions */
293 struct phy_driver *drv;
294
295 struct mii_bus *bus;
296
297 struct device dev;
298
299 u32 phy_id;
300
David Daneyac28b9f2012-06-27 07:33:35 +0000301 struct phy_c45_device_ids c45_ids;
302 bool is_c45;
Florian Fainelli4284b6a2013-05-23 01:11:12 +0000303 bool is_internal;
David Daneyac28b9f2012-06-27 07:33:35 +0000304
Andy Fleming00db8182005-07-30 19:31:23 -0400305 enum phy_state state;
306
307 u32 dev_flags;
308
Andy Fleminge8a2b6a2006-12-01 12:01:06 -0600309 phy_interface_t interface;
310
Peter Meerwaldc6883992010-09-02 04:06:24 +0000311 /* Bus address of the PHY (0-31) */
Andy Fleming00db8182005-07-30 19:31:23 -0400312 int addr;
313
Andy Flemingc5e38a92008-04-09 19:38:27 -0500314 /*
315 * forced speed & duplex (no autoneg)
Andy Fleming00db8182005-07-30 19:31:23 -0400316 * partner speed & duplex & pause (autoneg)
317 */
318 int speed;
319 int duplex;
320 int pause;
321 int asym_pause;
322
323 /* The most recently read link state */
324 int link;
325
326 /* Enabled Interrupts */
327 u32 interrupts;
328
329 /* Union of PHY and Attached devices' supported modes */
330 /* See mii.h for more info */
331 u32 supported;
332 u32 advertising;
333
334 int autoneg;
335
336 int link_timeout;
337
Andy Flemingc5e38a92008-04-09 19:38:27 -0500338 /*
339 * Interrupt number for this PHY
340 * -1 means no interrupt
341 */
Andy Fleming00db8182005-07-30 19:31:23 -0400342 int irq;
343
344 /* private data pointer */
345 /* For use by PHYs to maintain extra state */
346 void *priv;
347
348 /* Interrupt and Polling infrastructure */
349 struct work_struct phy_queue;
Marcin Slusarza390d1f2009-03-13 15:41:19 -0700350 struct delayed_work state_queue;
Maciej W. Rozycki0ac49522007-09-28 22:42:14 -0700351 atomic_t irq_disable;
Andy Fleming00db8182005-07-30 19:31:23 -0400352
Nate Case35b5f6b2008-01-29 10:05:09 -0600353 struct mutex lock;
Andy Fleming00db8182005-07-30 19:31:23 -0400354
355 struct net_device *attached_dev;
356
357 void (*adjust_link)(struct net_device *dev);
358
359 void (*adjust_state)(struct net_device *dev);
360};
361#define to_phy_device(d) container_of(d, struct phy_device, dev)
362
363/* struct phy_driver: Driver structure for a particular PHY type
364 *
365 * phy_id: The result of reading the UID registers of this PHY
366 * type, and ANDing them with the phy_id_mask. This driver
367 * only works for PHYs with IDs which match this field
368 * name: The friendly name of this PHY type
369 * phy_id_mask: Defines the important bits of the phy_id
370 * features: A list of features (speed, duplex, etc) supported
371 * by this PHY
372 * flags: A bitfield defining certain other features this PHY
373 * supports (like interrupts)
374 *
375 * The drivers must implement config_aneg and read_status. All
376 * other functions are optional. Note that none of these
377 * functions should be called from interrupt time. The goal is
378 * for the bus read/write functions to be able to block when the
379 * bus transaction is happening, and be freed up by an interrupt
380 * (The MPC85xx has this ability, though it is not currently
381 * supported in the driver).
382 */
383struct phy_driver {
384 u32 phy_id;
385 char *name;
386 unsigned int phy_id_mask;
387 u32 features;
388 u32 flags;
389
Andy Flemingc5e38a92008-04-09 19:38:27 -0500390 /*
391 * Called to initialize the PHY,
392 * including after a reset
393 */
Andy Fleming00db8182005-07-30 19:31:23 -0400394 int (*config_init)(struct phy_device *phydev);
395
Andy Flemingc5e38a92008-04-09 19:38:27 -0500396 /*
397 * Called during discovery. Used to set
398 * up device-specific structures, if any
399 */
Andy Fleming00db8182005-07-30 19:31:23 -0400400 int (*probe)(struct phy_device *phydev);
401
402 /* PHY Power Management */
403 int (*suspend)(struct phy_device *phydev);
404 int (*resume)(struct phy_device *phydev);
405
Andy Flemingc5e38a92008-04-09 19:38:27 -0500406 /*
407 * Configures the advertisement and resets
Andy Fleming00db8182005-07-30 19:31:23 -0400408 * autonegotiation if phydev->autoneg is on,
409 * forces the speed to the current settings in phydev
Andy Flemingc5e38a92008-04-09 19:38:27 -0500410 * if phydev->autoneg is off
411 */
Andy Fleming00db8182005-07-30 19:31:23 -0400412 int (*config_aneg)(struct phy_device *phydev);
413
414 /* Determines the negotiated speed and duplex */
415 int (*read_status)(struct phy_device *phydev);
416
417 /* Clears any pending interrupts */
418 int (*ack_interrupt)(struct phy_device *phydev);
419
420 /* Enables or disables interrupts */
421 int (*config_intr)(struct phy_device *phydev);
422
Anatolij Gustschina8729eb2009-04-07 02:01:42 +0000423 /*
424 * Checks if the PHY generated an interrupt.
425 * For multi-PHY devices with shared PHY interrupt pin
426 */
427 int (*did_interrupt)(struct phy_device *phydev);
428
Andy Fleming00db8182005-07-30 19:31:23 -0400429 /* Clears up any memory if needed */
430 void (*remove)(struct phy_device *phydev);
431
David Daneya30e2c12012-06-27 07:33:37 +0000432 /* Returns true if this is a suitable driver for the given
433 * phydev. If NULL, matching is based on phy_id and
434 * phy_id_mask.
435 */
436 int (*match_phy_device)(struct phy_device *phydev);
437
Richard Cochranc8f3a8c2012-04-03 22:59:17 +0000438 /* Handles ethtool queries for hardware time stamping. */
439 int (*ts_info)(struct phy_device *phydev, struct ethtool_ts_info *ti);
440
Richard Cochranc1f19b52010-07-17 08:49:36 +0000441 /* Handles SIOCSHWTSTAMP ioctl for hardware time stamping. */
442 int (*hwtstamp)(struct phy_device *phydev, struct ifreq *ifr);
443
444 /*
445 * Requests a Rx timestamp for 'skb'. If the skb is accepted,
446 * the phy driver promises to deliver it using netif_rx() as
447 * soon as a timestamp becomes available. One of the
448 * PTP_CLASS_ values is passed in 'type'. The function must
449 * return true if the skb is accepted for delivery.
450 */
451 bool (*rxtstamp)(struct phy_device *dev, struct sk_buff *skb, int type);
452
453 /*
454 * Requests a Tx timestamp for 'skb'. The phy driver promises
Richard Cochranda92b192011-10-21 00:49:15 +0000455 * to deliver it using skb_complete_tx_timestamp() as soon as a
Richard Cochranc1f19b52010-07-17 08:49:36 +0000456 * timestamp becomes available. One of the PTP_CLASS_ values
457 * is passed in 'type'.
458 */
459 void (*txtstamp)(struct phy_device *dev, struct sk_buff *skb, int type);
460
Michael Stapelberg42e836e2013-03-11 13:56:44 +0000461 /* Some devices (e.g. qnap TS-119P II) require PHY register changes to
462 * enable Wake on LAN, so set_wol is provided to be called in the
463 * ethernet driver's set_wol function. */
464 int (*set_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
465
466 /* See set_wol, but for checking whether Wake on LAN is enabled. */
467 void (*get_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
468
Andy Fleming00db8182005-07-30 19:31:23 -0400469 struct device_driver driver;
470};
471#define to_phy_driver(d) container_of(d, struct phy_driver, driver)
472
Andy Flemingf62220d2008-04-18 17:29:54 -0500473#define PHY_ANY_ID "MATCH ANY PHY"
474#define PHY_ANY_UID 0xffffffff
475
476/* A Structure for boards to register fixups with the PHY Lib */
477struct phy_fixup {
478 struct list_head list;
David S. Miller8e401ec2009-05-26 21:16:25 -0700479 char bus_id[20];
Andy Flemingf62220d2008-04-18 17:29:54 -0500480 u32 phy_uid;
481 u32 phy_uid_mask;
482 int (*run)(struct phy_device *phydev);
483};
484
Lennert Buytenhek2e888102008-09-29 17:12:35 +0000485/**
486 * phy_read - Convenience function for reading a given PHY register
487 * @phydev: the phy_device struct
488 * @regnum: register number to read
489 *
490 * NOTE: MUST NOT be called from interrupt context,
491 * because the bus read/write functions may wait for an interrupt
492 * to conclude the operation.
493 */
Jason Gunthorpeabf35df2010-03-09 09:17:42 +0000494static inline int phy_read(struct phy_device *phydev, u32 regnum)
Lennert Buytenhek2e888102008-09-29 17:12:35 +0000495{
496 return mdiobus_read(phydev->bus, phydev->addr, regnum);
497}
498
499/**
500 * phy_write - Convenience function for writing a given PHY register
501 * @phydev: the phy_device struct
502 * @regnum: register number to write
503 * @val: value to write to @regnum
504 *
505 * NOTE: MUST NOT be called from interrupt context,
506 * because the bus read/write functions may wait for an interrupt
507 * to conclude the operation.
508 */
Jason Gunthorpeabf35df2010-03-09 09:17:42 +0000509static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
Lennert Buytenhek2e888102008-09-29 17:12:35 +0000510{
511 return mdiobus_write(phydev->bus, phydev->addr, regnum, val);
512}
513
Florian Fainelli2c7b4922013-05-19 22:53:42 +0000514/**
515 * phy_interrupt_is_valid - Convenience function for testing a given PHY irq
516 * @phydev: the phy_device struct
517 *
518 * NOTE: must be kept in sync with addition/removal of PHY_POLL and
519 * PHY_IGNORE_INTERRUPT
520 */
521static inline bool phy_interrupt_is_valid(struct phy_device *phydev)
522{
523 return phydev->irq != PHY_POLL && phydev->irq != PHY_IGNORE_INTERRUPT;
524}
525
Florian Fainelli4284b6a2013-05-23 01:11:12 +0000526/**
527 * phy_is_internal - Convenience function for testing if a PHY is internal
528 * @phydev: the phy_device struct
529 */
530static inline bool phy_is_internal(struct phy_device *phydev)
531{
532 return phydev->is_internal;
533}
534
David Daneyac28b9f2012-06-27 07:33:35 +0000535struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
536 bool is_c45, struct phy_c45_device_ids *c45_ids);
537struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
Grant Likely4dea5472009-04-25 12:52:46 +0000538int phy_device_register(struct phy_device *phy);
Anton Vorontsov2f5cb432009-12-30 08:23:30 +0000539int phy_init_hw(struct phy_device *phydev);
Andy Fleminge1393452005-08-24 18:46:21 -0500540struct phy_device * phy_attach(struct net_device *dev,
Florian Fainellif9a8f832013-01-14 00:52:52 +0000541 const char *bus_id, phy_interface_t interface);
Jiri Pirkof8f76db2010-02-04 10:23:02 -0800542struct phy_device *phy_find_first(struct mii_bus *bus);
Grant Likelyfa94f6d2009-04-25 12:52:51 +0000543int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
Florian Fainellif9a8f832013-01-14 00:52:52 +0000544 void (*handler)(struct net_device *),
Grant Likelyfa94f6d2009-04-25 12:52:51 +0000545 phy_interface_t interface);
Andy Flemingf62220d2008-04-18 17:29:54 -0500546struct phy_device * phy_connect(struct net_device *dev, const char *bus_id,
Florian Fainellif9a8f832013-01-14 00:52:52 +0000547 void (*handler)(struct net_device *),
Andy Fleminge8a2b6a2006-12-01 12:01:06 -0600548 phy_interface_t interface);
Andy Fleminge1393452005-08-24 18:46:21 -0500549void phy_disconnect(struct phy_device *phydev);
550void phy_detach(struct phy_device *phydev);
551void phy_start(struct phy_device *phydev);
552void phy_stop(struct phy_device *phydev);
553int phy_start_aneg(struct phy_device *phydev);
554
Andy Fleminge1393452005-08-24 18:46:21 -0500555int phy_stop_interrupts(struct phy_device *phydev);
Andy Fleming00db8182005-07-30 19:31:23 -0400556
557static inline int phy_read_status(struct phy_device *phydev) {
558 return phydev->drv->read_status(phydev);
559}
560
Andy Fleming00db8182005-07-30 19:31:23 -0400561int genphy_restart_aneg(struct phy_device *phydev);
562int genphy_config_aneg(struct phy_device *phydev);
563int genphy_update_link(struct phy_device *phydev);
564int genphy_read_status(struct phy_device *phydev);
Giuseppe Cavallaro0f0ca342008-11-28 16:24:56 -0800565int genphy_suspend(struct phy_device *phydev);
566int genphy_resume(struct phy_device *phydev);
Andy Fleming00db8182005-07-30 19:31:23 -0400567void phy_driver_unregister(struct phy_driver *drv);
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000568void phy_drivers_unregister(struct phy_driver *drv, int n);
Andy Fleming00db8182005-07-30 19:31:23 -0400569int phy_driver_register(struct phy_driver *new_driver);
Christian Hohnstaedtd5bf9072012-07-04 05:44:34 +0000570int phy_drivers_register(struct phy_driver *new_driver, int n);
Anton Vorontsov4f9c85a2010-01-18 05:37:16 +0000571void phy_state_machine(struct work_struct *work);
Florian Fainelli5ea94e72013-05-19 22:53:43 +0000572void phy_change(struct work_struct *work);
573void phy_mac_interrupt(struct phy_device *phydev, int new_link);
Andy Fleming00db8182005-07-30 19:31:23 -0400574void phy_start_machine(struct phy_device *phydev,
575 void (*handler)(struct net_device *));
576void phy_stop_machine(struct phy_device *phydev);
577int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd);
578int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd);
579int phy_mii_ioctl(struct phy_device *phydev,
Richard Cochran28b04112010-07-17 08:48:55 +0000580 struct ifreq *ifr, int cmd);
Andy Fleminge1393452005-08-24 18:46:21 -0500581int phy_start_interrupts(struct phy_device *phydev);
582void phy_print_status(struct phy_device *phydev);
Anton Vorontsov6f4a7f42007-12-04 16:17:33 +0300583void phy_device_free(struct phy_device *phydev);
Andy Fleming00db8182005-07-30 19:31:23 -0400584
Andy Flemingf62220d2008-04-18 17:29:54 -0500585int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
586 int (*run)(struct phy_device *));
587int phy_register_fixup_for_id(const char *bus_id,
588 int (*run)(struct phy_device *));
589int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
590 int (*run)(struct phy_device *));
591int phy_scan_fixups(struct phy_device *phydev);
592
Giuseppe CAVALLAROa59a4d12012-06-27 21:14:38 +0000593int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);
594int phy_get_eee_err(struct phy_device *phydev);
595int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data);
596int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
Michael Stapelberg42e836e2013-03-11 13:56:44 +0000597int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
598void phy_ethtool_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
Giuseppe CAVALLAROa59a4d12012-06-27 21:14:38 +0000599
Andy Fleming9b9a8bf2008-05-02 13:00:51 -0500600int __init mdio_bus_init(void);
601void mdio_bus_exit(void);
602
Andy Fleming00db8182005-07-30 19:31:23 -0400603extern struct bus_type mdio_bus_type;
Andy Fleming00db8182005-07-30 19:31:23 -0400604#endif /* __PHY_H */