Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux-2.6-block.git] / include / linux / phylink.h
CommitLineData
9525ae83
RK
1#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;
8fa7b9b6 10struct fwnode_handle;
9525ae83
RK
11struct net_device;
12
13enum {
14 MLO_PAUSE_NONE,
15 MLO_PAUSE_ASYM = BIT(0),
16 MLO_PAUSE_SYM = BIT(1),
17 MLO_PAUSE_RX = BIT(2),
18 MLO_PAUSE_TX = BIT(3),
19 MLO_PAUSE_TXRX_MASK = MLO_PAUSE_TX | MLO_PAUSE_RX,
20 MLO_PAUSE_AN = BIT(4),
21
22 MLO_AN_PHY = 0, /* Conventional PHY */
23 MLO_AN_FIXED, /* Fixed-link mode */
86a362c4 24 MLO_AN_INBAND, /* In-band protocol */
9525ae83
RK
25};
26
27static inline bool phylink_autoneg_inband(unsigned int mode)
28{
86a362c4 29 return mode == MLO_AN_INBAND;
9525ae83
RK
30}
31
8796c892
RK
32/**
33 * struct phylink_link_state - link state structure
34 * @advertising: ethtool bitmask containing advertised link modes
35 * @lp_advertising: ethtool bitmask containing link partner advertised link
36 * modes
37 * @interface: link &typedef phy_interface_t mode
38 * @speed: link speed, one of the SPEED_* constants.
39 * @duplex: link duplex mode, one of DUPLEX_* constants.
40 * @pause: link pause state, described by MLO_PAUSE_* constants.
41 * @link: true if the link is up.
42 * @an_enabled: true if autonegotiation is enabled/desired.
43 * @an_complete: true if autonegotiation has completed.
44 */
9525ae83
RK
45struct phylink_link_state {
46 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
47 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
8796c892 48 phy_interface_t interface;
9525ae83
RK
49 int speed;
50 int duplex;
51 int pause;
52 unsigned int link:1;
53 unsigned int an_enabled:1;
54 unsigned int an_complete:1;
55};
56
44cc27e4
IC
57enum phylink_op_type {
58 PHYLINK_NETDEV = 0,
43de6195 59 PHYLINK_DEV,
44cc27e4
IC
60};
61
62/**
63 * struct phylink_config - PHYLINK configuration structure
64 * @dev: a pointer to a struct device associated with the MAC
65 * @type: operation type of PHYLINK instance
66 */
67struct phylink_config {
68 struct device *dev;
69 enum phylink_op_type type;
70};
71
8796c892
RK
72/**
73 * struct phylink_mac_ops - MAC operations structure.
74 * @validate: Validate and update the link configuration.
75 * @mac_link_state: Read the current link state from the hardware.
76 * @mac_config: configure the MAC for the selected mode and state.
77 * @mac_an_restart: restart 802.3z BaseX autonegotiation.
78 * @mac_link_down: take the link down.
79 * @mac_link_up: allow the link to come up.
80 *
81 * The individual methods are described more fully below.
82 */
9525ae83 83struct phylink_mac_ops {
44cc27e4
IC
84 void (*validate)(struct phylink_config *config,
85 unsigned long *supported,
9525ae83 86 struct phylink_link_state *state);
44cc27e4 87 int (*mac_link_state)(struct phylink_config *config,
8796c892 88 struct phylink_link_state *state);
44cc27e4 89 void (*mac_config)(struct phylink_config *config, unsigned int mode,
9525ae83 90 const struct phylink_link_state *state);
44cc27e4
IC
91 void (*mac_an_restart)(struct phylink_config *config);
92 void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
c6ab3008 93 phy_interface_t interface);
44cc27e4 94 void (*mac_link_up)(struct phylink_config *config, unsigned int mode,
c6ab3008 95 phy_interface_t interface,
8796c892 96 struct phy_device *phy);
9525ae83
RK
97};
98
8796c892
RK
99#if 0 /* For kernel-doc purposes only. */
100/**
101 * validate - Validate and update the link configuration
44cc27e4 102 * @config: a pointer to a &struct phylink_config.
8796c892
RK
103 * @supported: ethtool bitmask for supported link modes.
104 * @state: a pointer to a &struct phylink_link_state.
105 *
106 * Clear bits in the @supported and @state->advertising masks that
107 * are not supportable by the MAC.
108 *
109 * Note that the PHY may be able to transform from one connection
110 * technology to another, so, eg, don't clear 1000BaseX just
111 * because the MAC is unable to BaseX mode. This is more about
32e454ef
RK
112 * clearing unsupported speeds and duplex settings. The port modes
113 * should not be cleared; phylink_set_port_modes() will help with this.
8796c892
RK
114 *
115 * If the @state->interface mode is %PHY_INTERFACE_MODE_1000BASEX
116 * or %PHY_INTERFACE_MODE_2500BASEX, select the appropriate mode
117 * based on @state->advertising and/or @state->speed and update
32e454ef
RK
118 * @state->interface accordingly. See phylink_helper_basex_speed().
119 *
120 * When @state->interface is %PHY_INTERFACE_MODE_NA, phylink expects the
121 * MAC driver to return all supported link modes.
122 *
123 * If the @state->interface mode is not supported, then the @supported
124 * mask must be cleared.
8796c892 125 */
44cc27e4 126void validate(struct phylink_config *config, unsigned long *supported,
8796c892
RK
127 struct phylink_link_state *state);
128
129/**
130 * mac_link_state() - Read the current link state from the hardware
44cc27e4 131 * @config: a pointer to a &struct phylink_config.
8796c892
RK
132 * @state: a pointer to a &struct phylink_link_state.
133 *
134 * Read the current link state from the MAC, reporting the current
135 * speed in @state->speed, duplex mode in @state->duplex, pause mode
136 * in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
137 * negotiation completion state in @state->an_complete, and link
138 * up state in @state->link.
139 */
44cc27e4 140int mac_link_state(struct phylink_config *config,
8796c892
RK
141 struct phylink_link_state *state);
142
143/**
144 * mac_config() - configure the MAC for the selected mode and state
44cc27e4 145 * @config: a pointer to a &struct phylink_config.
8796c892
RK
146 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
147 * @state: a pointer to a &struct phylink_link_state.
148 *
4add7009
RKAL
149 * Note - not all members of @state are valid. In particular,
150 * @state->lp_advertising, @state->link, @state->an_complete are never
151 * guaranteed to be correct, and so any mac_config() implementation must
152 * never reference these fields.
153 *
8796c892
RK
154 * The action performed depends on the currently selected mode:
155 *
156 * %MLO_AN_FIXED, %MLO_AN_PHY:
157 * Configure the specified @state->speed, @state->duplex and
4add7009
RKAL
158 * @state->pause (%MLO_PAUSE_TX / %MLO_PAUSE_RX) modes over a link
159 * specified by @state->interface. @state->advertising may be used,
160 * but is not required. Other members of @state must be ignored.
161 *
162 * Valid state members: interface, speed, duplex, pause, advertising.
8796c892
RK
163 *
164 * %MLO_AN_INBAND:
165 * place the link in an inband negotiation mode (such as 802.3z
166 * 1000base-X or Cisco SGMII mode depending on the @state->interface
167 * mode). In both cases, link state management (whether the link
168 * is up or not) is performed by the MAC, and reported via the
169 * mac_link_state() callback. Changes in link state must be made
170 * by calling phylink_mac_change().
171 *
172 * If in 802.3z mode, the link speed is fixed, dependent on the
173 * @state->interface. Duplex is negotiated, and pause is advertised
174 * according to @state->an_enabled, @state->pause and
175 * @state->advertising flags. Beware of MACs which only support full
176 * duplex at gigabit and higher speeds.
177 *
178 * If in Cisco SGMII mode, the link speed and duplex mode are passed
179 * in the serial bitstream 16-bit configuration word, and the MAC
180 * should be configured to read these bits and acknowledge the
181 * configuration word. Nothing is advertised by the MAC. The MAC is
182 * responsible for reading the configuration word and configuring
183 * itself accordingly.
0e29ae03 184 *
4add7009
RKAL
185 * Valid state members: interface, an_enabled, pause, advertising.
186 *
0e29ae03
RK
187 * Implementations are expected to update the MAC to reflect the
188 * requested settings - i.o.w., if nothing has changed between two
189 * calls, no action is expected. If only flow control settings have
190 * changed, flow control should be updated *without* taking the link
191 * down. This "update" behaviour is critical to avoid bouncing the
192 * link up status.
8796c892 193 */
44cc27e4 194void mac_config(struct phylink_config *config, unsigned int mode,
8796c892
RK
195 const struct phylink_link_state *state);
196
197/**
198 * mac_an_restart() - restart 802.3z BaseX autonegotiation
44cc27e4 199 * @config: a pointer to a &struct phylink_config.
8796c892 200 */
44cc27e4 201void mac_an_restart(struct phylink_config *config);
8796c892
RK
202
203/**
204 * mac_link_down() - take the link down
44cc27e4 205 * @config: a pointer to a &struct phylink_config.
8796c892 206 * @mode: link autonegotiation mode
c6ab3008 207 * @interface: link &typedef phy_interface_t mode
8796c892
RK
208 *
209 * If @mode is not an in-band negotiation mode (as defined by
210 * phylink_autoneg_inband()), force the link down and disable any
c6ab3008
FF
211 * Energy Efficient Ethernet MAC configuration. Interface type
212 * selection must be done in mac_config().
8796c892 213 */
44cc27e4 214void mac_link_down(struct phylink_config *config, unsigned int mode,
c6ab3008 215 phy_interface_t interface);
8796c892
RK
216
217/**
218 * mac_link_up() - allow the link to come up
44cc27e4 219 * @config: a pointer to a &struct phylink_config.
8796c892 220 * @mode: link autonegotiation mode
c6ab3008 221 * @interface: link &typedef phy_interface_t mode
8796c892
RK
222 * @phy: any attached phy
223 *
224 * If @mode is not an in-band negotiation mode (as defined by
225 * phylink_autoneg_inband()), allow the link to come up. If @phy
226 * is non-%NULL, configure Energy Efficient Ethernet by calling
227 * phy_init_eee() and perform appropriate MAC configuration for EEE.
c6ab3008 228 * Interface type selection must be done in mac_config().
8796c892 229 */
44cc27e4 230void mac_link_up(struct phylink_config *config, unsigned int mode,
c6ab3008 231 phy_interface_t interface,
8796c892
RK
232 struct phy_device *phy);
233#endif
234
44cc27e4
IC
235struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *,
236 phy_interface_t iface,
237 const struct phylink_mac_ops *ops);
9525ae83
RK
238void phylink_destroy(struct phylink *);
239
240int phylink_connect_phy(struct phylink *, struct phy_device *);
0a62964c 241int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
9525ae83 242void phylink_disconnect_phy(struct phylink *);
1ac63e39
FF
243int phylink_fixed_state_cb(struct phylink *,
244 void (*cb)(struct net_device *dev,
245 struct phylink_link_state *));
9525ae83
RK
246
247void phylink_mac_change(struct phylink *, bool up);
248
249void phylink_start(struct phylink *);
250void phylink_stop(struct phylink *);
251
252void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
253int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
254
255int phylink_ethtool_ksettings_get(struct phylink *,
256 struct ethtool_link_ksettings *);
257int phylink_ethtool_ksettings_set(struct phylink *,
258 const struct ethtool_link_ksettings *);
259int phylink_ethtool_nway_reset(struct phylink *);
260void phylink_ethtool_get_pauseparam(struct phylink *,
261 struct ethtool_pauseparam *);
262int phylink_ethtool_set_pauseparam(struct phylink *,
263 struct ethtool_pauseparam *);
9525ae83 264int phylink_get_eee_err(struct phylink *);
86e58135 265int phylink_init_eee(struct phylink *, bool);
9525ae83
RK
266int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
267int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
268int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
269
270#define phylink_zero(bm) \
271 bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
272#define __phylink_do_bit(op, bm, mode) \
273 op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
274
275#define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode)
276#define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
277#define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode)
278
279void phylink_set_port_modes(unsigned long *bits);
624c0f02 280void phylink_helper_basex_speed(struct phylink_link_state *state);
9525ae83
RK
281
282#endif