drm/panfrost: Remove set but not used variable 'bo'
[linux/fpc-iii.git] / include / linux / phylink.h
blob523209e70947309a167e34d6a76759ff783f7a55
1 #ifndef NETDEV_PCS_H
2 #define NETDEV_PCS_H
4 #include <linux/phy.h>
5 #include <linux/spinlock.h>
6 #include <linux/workqueue.h>
8 struct device_node;
9 struct ethtool_cmd;
10 struct fwnode_handle;
11 struct net_device;
13 enum {
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),
22 MLO_AN_PHY = 0, /* Conventional PHY */
23 MLO_AN_FIXED, /* Fixed-link mode */
24 MLO_AN_INBAND, /* In-band protocol */
27 static inline bool phylink_autoneg_inband(unsigned int mode)
29 return mode == MLO_AN_INBAND;
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.
45 struct phylink_link_state {
46 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
47 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
48 phy_interface_t interface;
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;
57 enum phylink_op_type {
58 PHYLINK_NETDEV = 0,
59 PHYLINK_DEV,
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 * @pcs_poll: MAC PCS cannot provide link change interrupt
68 struct phylink_config {
69 struct device *dev;
70 enum phylink_op_type type;
71 bool pcs_poll;
74 /**
75 * struct phylink_mac_ops - MAC operations structure.
76 * @validate: Validate and update the link configuration.
77 * @mac_pcs_get_state: Read the current link state from the hardware.
78 * @mac_config: configure the MAC for the selected mode and state.
79 * @mac_an_restart: restart 802.3z BaseX autonegotiation.
80 * @mac_link_down: take the link down.
81 * @mac_link_up: allow the link to come up.
83 * The individual methods are described more fully below.
85 struct phylink_mac_ops {
86 void (*validate)(struct phylink_config *config,
87 unsigned long *supported,
88 struct phylink_link_state *state);
89 void (*mac_pcs_get_state)(struct phylink_config *config,
90 struct phylink_link_state *state);
91 void (*mac_config)(struct phylink_config *config, unsigned int mode,
92 const struct phylink_link_state *state);
93 void (*mac_an_restart)(struct phylink_config *config);
94 void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
95 phy_interface_t interface);
96 void (*mac_link_up)(struct phylink_config *config, unsigned int mode,
97 phy_interface_t interface,
98 struct phy_device *phy);
101 #if 0 /* For kernel-doc purposes only. */
103 * validate - Validate and update the link configuration
104 * @config: a pointer to a &struct phylink_config.
105 * @supported: ethtool bitmask for supported link modes.
106 * @state: a pointer to a &struct phylink_link_state.
108 * Clear bits in the @supported and @state->advertising masks that
109 * are not supportable by the MAC.
111 * Note that the PHY may be able to transform from one connection
112 * technology to another, so, eg, don't clear 1000BaseX just
113 * because the MAC is unable to BaseX mode. This is more about
114 * clearing unsupported speeds and duplex settings. The port modes
115 * should not be cleared; phylink_set_port_modes() will help with this.
117 * If the @state->interface mode is %PHY_INTERFACE_MODE_1000BASEX
118 * or %PHY_INTERFACE_MODE_2500BASEX, select the appropriate mode
119 * based on @state->advertising and/or @state->speed and update
120 * @state->interface accordingly. See phylink_helper_basex_speed().
122 * When @state->interface is %PHY_INTERFACE_MODE_NA, phylink expects the
123 * MAC driver to return all supported link modes.
125 * If the @state->interface mode is not supported, then the @supported
126 * mask must be cleared.
128 void validate(struct phylink_config *config, unsigned long *supported,
129 struct phylink_link_state *state);
132 * mac_pcs_get_state() - Read the current inband link state from the hardware
133 * @config: a pointer to a &struct phylink_config.
134 * @state: a pointer to a &struct phylink_link_state.
136 * Read the current inband link state from the MAC PCS, reporting the
137 * current speed in @state->speed, duplex mode in @state->duplex, pause
138 * mode in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
139 * negotiation completion state in @state->an_complete, and link up state
140 * in @state->link. If possible, @state->lp_advertising should also be
141 * populated.
143 void mac_pcs_get_state(struct phylink_config *config,
144 struct phylink_link_state *state);
147 * mac_config() - configure the MAC for the selected mode and state
148 * @config: a pointer to a &struct phylink_config.
149 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
150 * @state: a pointer to a &struct phylink_link_state.
152 * Note - not all members of @state are valid. In particular,
153 * @state->lp_advertising, @state->link, @state->an_complete are never
154 * guaranteed to be correct, and so any mac_config() implementation must
155 * never reference these fields.
157 * The action performed depends on the currently selected mode:
159 * %MLO_AN_FIXED, %MLO_AN_PHY:
160 * Configure the specified @state->speed, @state->duplex and
161 * @state->pause (%MLO_PAUSE_TX / %MLO_PAUSE_RX) modes over a link
162 * specified by @state->interface. @state->advertising may be used,
163 * but is not required. Other members of @state must be ignored.
165 * Valid state members: interface, speed, duplex, pause, advertising.
167 * %MLO_AN_INBAND:
168 * place the link in an inband negotiation mode (such as 802.3z
169 * 1000base-X or Cisco SGMII mode depending on the @state->interface
170 * mode). In both cases, link state management (whether the link
171 * is up or not) is performed by the MAC, and reported via the
172 * mac_pcs_get_state() callback. Changes in link state must be made
173 * by calling phylink_mac_change().
175 * If in 802.3z mode, the link speed is fixed, dependent on the
176 * @state->interface. Duplex is negotiated, and pause is advertised
177 * according to @state->an_enabled, @state->pause and
178 * @state->advertising flags. Beware of MACs which only support full
179 * duplex at gigabit and higher speeds.
181 * If in Cisco SGMII mode, the link speed and duplex mode are passed
182 * in the serial bitstream 16-bit configuration word, and the MAC
183 * should be configured to read these bits and acknowledge the
184 * configuration word. Nothing is advertised by the MAC. The MAC is
185 * responsible for reading the configuration word and configuring
186 * itself accordingly.
188 * Valid state members: interface, an_enabled, pause, advertising.
190 * Implementations are expected to update the MAC to reflect the
191 * requested settings - i.o.w., if nothing has changed between two
192 * calls, no action is expected. If only flow control settings have
193 * changed, flow control should be updated *without* taking the link
194 * down. This "update" behaviour is critical to avoid bouncing the
195 * link up status.
197 void mac_config(struct phylink_config *config, unsigned int mode,
198 const struct phylink_link_state *state);
201 * mac_an_restart() - restart 802.3z BaseX autonegotiation
202 * @config: a pointer to a &struct phylink_config.
204 void mac_an_restart(struct phylink_config *config);
207 * mac_link_down() - take the link down
208 * @config: a pointer to a &struct phylink_config.
209 * @mode: link autonegotiation mode
210 * @interface: link &typedef phy_interface_t mode
212 * If @mode is not an in-band negotiation mode (as defined by
213 * phylink_autoneg_inband()), force the link down and disable any
214 * Energy Efficient Ethernet MAC configuration. Interface type
215 * selection must be done in mac_config().
217 void mac_link_down(struct phylink_config *config, unsigned int mode,
218 phy_interface_t interface);
221 * mac_link_up() - allow the link to come up
222 * @config: a pointer to a &struct phylink_config.
223 * @mode: link autonegotiation mode
224 * @interface: link &typedef phy_interface_t mode
225 * @phy: any attached phy
227 * If @mode is not an in-band negotiation mode (as defined by
228 * phylink_autoneg_inband()), allow the link to come up. If @phy
229 * is non-%NULL, configure Energy Efficient Ethernet by calling
230 * phy_init_eee() and perform appropriate MAC configuration for EEE.
231 * Interface type selection must be done in mac_config().
233 void mac_link_up(struct phylink_config *config, unsigned int mode,
234 phy_interface_t interface,
235 struct phy_device *phy);
236 #endif
238 struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *,
239 phy_interface_t iface,
240 const struct phylink_mac_ops *ops);
241 void phylink_destroy(struct phylink *);
243 int phylink_connect_phy(struct phylink *, struct phy_device *);
244 int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
245 void phylink_disconnect_phy(struct phylink *);
246 int phylink_fixed_state_cb(struct phylink *,
247 void (*cb)(struct net_device *dev,
248 struct phylink_link_state *));
250 void phylink_mac_change(struct phylink *, bool up);
252 void phylink_start(struct phylink *);
253 void phylink_stop(struct phylink *);
255 void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
256 int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
258 int phylink_ethtool_ksettings_get(struct phylink *,
259 struct ethtool_link_ksettings *);
260 int phylink_ethtool_ksettings_set(struct phylink *,
261 const struct ethtool_link_ksettings *);
262 int phylink_ethtool_nway_reset(struct phylink *);
263 void phylink_ethtool_get_pauseparam(struct phylink *,
264 struct ethtool_pauseparam *);
265 int phylink_ethtool_set_pauseparam(struct phylink *,
266 struct ethtool_pauseparam *);
267 int phylink_get_eee_err(struct phylink *);
268 int phylink_init_eee(struct phylink *, bool);
269 int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
270 int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
271 int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
273 #define phylink_zero(bm) \
274 bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
275 #define __phylink_do_bit(op, bm, mode) \
276 op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
278 #define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode)
279 #define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
280 #define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode)
282 void phylink_set_port_modes(unsigned long *bits);
283 void phylink_helper_basex_speed(struct phylink_link_state *state);
285 #endif