blob: cab22ad3bd6fe3fce6bf6b72c44251cbaf1503e0 [file] [log] [blame]
Russell King9525ae82017-07-25 15:03:13 +01001#ifndef NETDEV_PCS_H
2#define NETDEV_PCS_H
3
4#include <linux/phy.h>
5#include <linux/spinlock.h>
6#include <linux/workqueue.h>
7
8struct device_node;
9struct ethtool_cmd;
10struct net_device;
11
12enum {
13 MLO_PAUSE_NONE,
14 MLO_PAUSE_ASYM = BIT(0),
15 MLO_PAUSE_SYM = BIT(1),
16 MLO_PAUSE_RX = BIT(2),
17 MLO_PAUSE_TX = BIT(3),
18 MLO_PAUSE_TXRX_MASK = MLO_PAUSE_TX | MLO_PAUSE_RX,
19 MLO_PAUSE_AN = BIT(4),
20
21 MLO_AN_PHY = 0, /* Conventional PHY */
22 MLO_AN_FIXED, /* Fixed-link mode */
Russell King86a362c2017-12-01 10:24:26 +000023 MLO_AN_INBAND, /* In-band protocol */
Russell King9525ae82017-07-25 15:03:13 +010024};
25
26static inline bool phylink_autoneg_inband(unsigned int mode)
27{
Russell King86a362c2017-12-01 10:24:26 +000028 return mode == MLO_AN_INBAND;
Russell King9525ae82017-07-25 15:03:13 +010029}
30
31struct phylink_link_state {
32 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
33 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
34 phy_interface_t interface; /* PHY_INTERFACE_xxx */
35 int speed;
36 int duplex;
37 int pause;
38 unsigned int link:1;
39 unsigned int an_enabled:1;
40 unsigned int an_complete:1;
41};
42
43struct phylink_mac_ops {
44 /**
45 * validate: validate and update the link configuration
46 * @ndev: net_device structure associated with MAC
47 * @config: configuration to validate
48 *
49 * Update the %config->supported and %config->advertised masks
50 * clearing bits that can not be supported.
51 *
52 * Note: the PHY may be able to transform from one connection
53 * technology to another, so, eg, don't clear 1000BaseX just
54 * because the MAC is unable to support it. This is more about
55 * clearing unsupported speeds and duplex settings.
56 *
57 * If the %config->interface mode is %PHY_INTERFACE_MODE_1000BASEX
58 * or %PHY_INTERFACE_MODE_2500BASEX, select the appropriate mode
59 * based on %config->advertised and/or %config->speed.
60 */
61 void (*validate)(struct net_device *ndev, unsigned long *supported,
62 struct phylink_link_state *state);
63
64 /* Read the current link state from the hardware */
65 int (*mac_link_state)(struct net_device *, struct phylink_link_state *);
66
67 /* Configure the MAC */
68 /**
69 * mac_config: configure the MAC for the selected mode and state
70 * @ndev: net_device structure for the MAC
Russell King86a362c2017-12-01 10:24:26 +000071 * @mode: one of MLO_AN_FIXED, MLO_AN_PHY, MLO_AN_INBAND
Russell King9525ae82017-07-25 15:03:13 +010072 * @state: state structure
73 *
74 * The action performed depends on the currently selected mode:
75 *
76 * %MLO_AN_FIXED, %MLO_AN_PHY:
77 * set the specified speed, duplex, pause mode, and phy interface
78 * mode in the provided @state.
Russell King86a362c2017-12-01 10:24:26 +000079 * %MLO_AN_INBAND:
80 * place the link in an inband negotiation mode (such as
81 * 1000base-X or Cisco SGMII mode depending on the phy interface
82 * mode), advertising the parameters given in advertising in @state.
Russell King9525ae82017-07-25 15:03:13 +010083 */
84 void (*mac_config)(struct net_device *ndev, unsigned int mode,
85 const struct phylink_link_state *state);
86
87 /**
88 * mac_an_restart: restart 802.3z BaseX autonegotiation
89 * @ndev: net_device structure for the MAC
90 */
91 void (*mac_an_restart)(struct net_device *ndev);
92
93 void (*mac_link_down)(struct net_device *, unsigned int mode);
94 void (*mac_link_up)(struct net_device *, unsigned int mode,
95 struct phy_device *);
96};
97
98struct phylink *phylink_create(struct net_device *, struct device_node *,
99 phy_interface_t iface, const struct phylink_mac_ops *ops);
100void phylink_destroy(struct phylink *);
101
102int phylink_connect_phy(struct phylink *, struct phy_device *);
103int phylink_of_phy_connect(struct phylink *, struct device_node *);
104void phylink_disconnect_phy(struct phylink *);
105
106void phylink_mac_change(struct phylink *, bool up);
107
108void phylink_start(struct phylink *);
109void phylink_stop(struct phylink *);
110
111void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
112int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
113
114int phylink_ethtool_ksettings_get(struct phylink *,
115 struct ethtool_link_ksettings *);
116int phylink_ethtool_ksettings_set(struct phylink *,
117 const struct ethtool_link_ksettings *);
118int phylink_ethtool_nway_reset(struct phylink *);
119void phylink_ethtool_get_pauseparam(struct phylink *,
120 struct ethtool_pauseparam *);
121int phylink_ethtool_set_pauseparam(struct phylink *,
122 struct ethtool_pauseparam *);
Russell King770a1ad2017-07-25 15:03:23 +0100123int phylink_ethtool_get_module_info(struct phylink *, struct ethtool_modinfo *);
124int phylink_ethtool_get_module_eeprom(struct phylink *,
125 struct ethtool_eeprom *, u8 *);
Russell King9525ae82017-07-25 15:03:13 +0100126int phylink_init_eee(struct phylink *, bool);
127int phylink_get_eee_err(struct phylink *);
128int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
129int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
130int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
131
132#define phylink_zero(bm) \
133 bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
134#define __phylink_do_bit(op, bm, mode) \
135 op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
136
137#define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode)
138#define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
139#define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode)
140
141void phylink_set_port_modes(unsigned long *bits);
142
143#endif