5 #include <linux/spinlock.h>
6 #include <linux/workqueue.h>
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;
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
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;
53 unsigned int an_enabled:1;
54 unsigned int an_complete:1;
58 * struct phylink_mac_ops - MAC operations structure.
59 * @validate: Validate and update the link configuration.
60 * @mac_link_state: Read the current link state from the hardware.
61 * @mac_config: configure the MAC for the selected mode and state.
62 * @mac_an_restart: restart 802.3z BaseX autonegotiation.
63 * @mac_link_down: take the link down.
64 * @mac_link_up: allow the link to come up.
66 * The individual methods are described more fully below.
68 struct phylink_mac_ops {
69 void (*validate)(struct net_device *ndev, unsigned long *supported,
70 struct phylink_link_state *state);
71 int (*mac_link_state)(struct net_device *ndev,
72 struct phylink_link_state *state);
73 void (*mac_config)(struct net_device *ndev, unsigned int mode,
74 const struct phylink_link_state *state);
75 void (*mac_an_restart)(struct net_device *ndev);
76 void (*mac_link_down)(struct net_device *ndev, unsigned int mode,
77 phy_interface_t interface);
78 void (*mac_link_up)(struct net_device *ndev, unsigned int mode,
79 phy_interface_t interface,
80 struct phy_device *phy);
83 #if 0 /* For kernel-doc purposes only. */
85 * validate - Validate and update the link configuration
86 * @ndev: a pointer to a &struct net_device for the MAC.
87 * @supported: ethtool bitmask for supported link modes.
88 * @state: a pointer to a &struct phylink_link_state.
90 * Clear bits in the @supported and @state->advertising masks that
91 * are not supportable by the MAC.
93 * Note that the PHY may be able to transform from one connection
94 * technology to another, so, eg, don't clear 1000BaseX just
95 * because the MAC is unable to BaseX mode. This is more about
96 * clearing unsupported speeds and duplex settings.
98 * If the @state->interface mode is %PHY_INTERFACE_MODE_1000BASEX
99 * or %PHY_INTERFACE_MODE_2500BASEX, select the appropriate mode
100 * based on @state->advertising and/or @state->speed and update
101 * @state->interface accordingly.
103 void validate(struct net_device *ndev, unsigned long *supported,
104 struct phylink_link_state *state);
107 * mac_link_state() - Read the current link state from the hardware
108 * @ndev: a pointer to a &struct net_device for the MAC.
109 * @state: a pointer to a &struct phylink_link_state.
111 * Read the current link state from the MAC, reporting the current
112 * speed in @state->speed, duplex mode in @state->duplex, pause mode
113 * in @state->pause using the %MLO_PAUSE_RX and %MLO_PAUSE_TX bits,
114 * negotiation completion state in @state->an_complete, and link
115 * up state in @state->link.
117 int mac_link_state(struct net_device *ndev,
118 struct phylink_link_state *state);
121 * mac_config() - configure the MAC for the selected mode and state
122 * @ndev: a pointer to a &struct net_device for the MAC.
123 * @mode: one of %MLO_AN_FIXED, %MLO_AN_PHY, %MLO_AN_INBAND.
124 * @state: a pointer to a &struct phylink_link_state.
126 * Note - not all members of @state are valid. In particular,
127 * @state->lp_advertising, @state->link, @state->an_complete are never
128 * guaranteed to be correct, and so any mac_config() implementation must
129 * never reference these fields.
131 * The action performed depends on the currently selected mode:
133 * %MLO_AN_FIXED, %MLO_AN_PHY:
134 * Configure the specified @state->speed, @state->duplex and
135 * @state->pause (%MLO_PAUSE_TX / %MLO_PAUSE_RX) modes over a link
136 * specified by @state->interface. @state->advertising may be used,
137 * but is not required. Other members of @state must be ignored.
139 * Valid state members: interface, speed, duplex, pause, advertising.
142 * place the link in an inband negotiation mode (such as 802.3z
143 * 1000base-X or Cisco SGMII mode depending on the @state->interface
144 * mode). In both cases, link state management (whether the link
145 * is up or not) is performed by the MAC, and reported via the
146 * mac_link_state() callback. Changes in link state must be made
147 * by calling phylink_mac_change().
149 * If in 802.3z mode, the link speed is fixed, dependent on the
150 * @state->interface. Duplex is negotiated, and pause is advertised
151 * according to @state->an_enabled, @state->pause and
152 * @state->advertising flags. Beware of MACs which only support full
153 * duplex at gigabit and higher speeds.
155 * If in Cisco SGMII mode, the link speed and duplex mode are passed
156 * in the serial bitstream 16-bit configuration word, and the MAC
157 * should be configured to read these bits and acknowledge the
158 * configuration word. Nothing is advertised by the MAC. The MAC is
159 * responsible for reading the configuration word and configuring
160 * itself accordingly.
162 * Valid state members: interface, an_enabled, pause, advertising.
164 * Implementations are expected to update the MAC to reflect the
165 * requested settings - i.o.w., if nothing has changed between two
166 * calls, no action is expected. If only flow control settings have
167 * changed, flow control should be updated *without* taking the link
168 * down. This "update" behaviour is critical to avoid bouncing the
171 void mac_config(struct net_device *ndev, unsigned int mode,
172 const struct phylink_link_state *state);
175 * mac_an_restart() - restart 802.3z BaseX autonegotiation
176 * @ndev: a pointer to a &struct net_device for the MAC.
178 void mac_an_restart(struct net_device *ndev);
181 * mac_link_down() - take the link down
182 * @ndev: a pointer to a &struct net_device for the MAC.
183 * @mode: link autonegotiation mode
184 * @interface: link &typedef phy_interface_t mode
186 * If @mode is not an in-band negotiation mode (as defined by
187 * phylink_autoneg_inband()), force the link down and disable any
188 * Energy Efficient Ethernet MAC configuration. Interface type
189 * selection must be done in mac_config().
191 void mac_link_down(struct net_device *ndev, unsigned int mode,
192 phy_interface_t interface);
195 * mac_link_up() - allow the link to come up
196 * @ndev: a pointer to a &struct net_device for the MAC.
197 * @mode: link autonegotiation mode
198 * @interface: link &typedef phy_interface_t mode
199 * @phy: any attached phy
201 * If @mode is not an in-band negotiation mode (as defined by
202 * phylink_autoneg_inband()), allow the link to come up. If @phy
203 * is non-%NULL, configure Energy Efficient Ethernet by calling
204 * phy_init_eee() and perform appropriate MAC configuration for EEE.
205 * Interface type selection must be done in mac_config().
207 void mac_link_up(struct net_device *ndev, unsigned int mode,
208 phy_interface_t interface,
209 struct phy_device *phy);
212 struct phylink *phylink_create(struct net_device *, struct fwnode_handle *,
213 phy_interface_t iface, const struct phylink_mac_ops *ops);
214 void phylink_destroy(struct phylink *);
216 int phylink_connect_phy(struct phylink *, struct phy_device *);
217 int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
218 void phylink_disconnect_phy(struct phylink *);
219 int phylink_fixed_state_cb(struct phylink *,
220 void (*cb)(struct net_device *dev,
221 struct phylink_link_state *));
223 void phylink_mac_change(struct phylink *, bool up);
225 void phylink_start(struct phylink *);
226 void phylink_stop(struct phylink *);
228 void phylink_ethtool_get_wol(struct phylink *, struct ethtool_wolinfo *);
229 int phylink_ethtool_set_wol(struct phylink *, struct ethtool_wolinfo *);
231 int phylink_ethtool_ksettings_get(struct phylink *,
232 struct ethtool_link_ksettings *);
233 int phylink_ethtool_ksettings_set(struct phylink *,
234 const struct ethtool_link_ksettings *);
235 int phylink_ethtool_nway_reset(struct phylink *);
236 void phylink_ethtool_get_pauseparam(struct phylink *,
237 struct ethtool_pauseparam *);
238 int phylink_ethtool_set_pauseparam(struct phylink *,
239 struct ethtool_pauseparam *);
240 int phylink_get_eee_err(struct phylink *);
241 int phylink_init_eee(struct phylink *, bool);
242 int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
243 int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
244 int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
246 #define phylink_zero(bm) \
247 bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
248 #define __phylink_do_bit(op, bm, mode) \
249 op(ETHTOOL_LINK_MODE_ ## mode ## _BIT, bm)
251 #define phylink_set(bm, mode) __phylink_do_bit(__set_bit, bm, mode)
252 #define phylink_clear(bm, mode) __phylink_do_bit(__clear_bit, bm, mode)
253 #define phylink_test(bm, mode) __phylink_do_bit(test_bit, bm, mode)
255 void phylink_set_port_modes(unsigned long *bits);
256 void phylink_helper_basex_speed(struct phylink_link_state *state);